Private Sub HSVtoRGB(ByRef Red, ByRef Green, ByRef Blue, Hue, Sat, Value)
   Dim i As Long
   Dim f As Double, p As Double, q As Double, t As Double
  Â
   If Sat = 0 Then
       Red = Value
       Green = Value
       Blue = Value
       Exit Sub
   End If
  Â
   i = Hue 60
   Hue = Hue / 60
   f = Hue – i
   p = Value * (1 – Sat)
   q = Value * (1 – Sat * f)
   t = Value * (1 – Sat * (1 – f))
  Â
   Select Case i
       Case 0
           Red = Value
           Green = t
           Blue = p
       Case 1
           Red = q
           Green = Value
           Blue = p
       Case 2
           Red = p
           Green = Value
           Blue = t
       Case 3
           Red = p
           Green = q
           Blue = Value
       Case 4
           Red = t
           Green = p
           Blue = Value
       Case 5
           Red = Value
           Green = p
           Blue = q
   End Select
  Â
End Sub
Â
'Function RGBtoHSV(Red, Green, Blue, ByRef Hue, ByRef Sat, ByRef Value)
'Â Â Â Dim Temp As Double
'Â Â Â Dim xa As Double
'Â Â Â Dim ya As Double
'
'Â Â Â Temp = (Red + Green + Blue) / 3
'   xa = (Green – Red) / Sqr(2)
'   ya = (Blue + Blue – Red – Green) / Sqr(6)
'Â Â Â Hue = Arg(xa, ya) * 180 / pi + 150
'   Sat = Arg(Temp, Module(Red – Temp, Green – Temp, Blue – Temp)) * 100 / Atn(Sqr(6))
'Â Â Â Value = Temp / 2.55
'
'Â Â Â If Sat = 0 Or Value = 0 Then Hue = 0
'Â Â Â If Hue < 0 Then Hue = Hue + 360
'   If Hue >= 360 Then Hue = Hue – 360
'End Function
Â
Sub RGBtoHSV(Red, Green, Blue, ByRef Hue, ByRef Sat, ByRef Value)
   Dim min As Double, max As Double, delta As Double
   If Red <= Green And Red <= Blue Then min = Red
   If Green <= Red And Green <= Blue Then min = Green
   If Blue <= Red And Blue <= Green Then min = Blue
  Â
   If Red >= Green And Red >= Blue Then max = Red
   If Green >= Red And Green >= Blue Then max = Green
   If Blue >= Red And Blue >= Green Then max = Blue
  Â
   Value = max
   delta = max – min
  Â
   If Not delta = 0 Then
       Sat = delta / max
   Else
       Sat = 0
       Hue = 0
       Exit Sub
   End If
  Â
   If Red = max Then
       Hue = (Green – Blue) / delta
   ElseIf Green = max Then
       Hue = 2 + (Blue – Red)
   Else
       Hue = 4 + (Red – Green) / delta
   End If
   Hue = Hue * 60
   If Hue < 0 Then Hue = Hue + 360
End Sub
Â
Private Sub UnRGB(ByVal Color As OLE_COLOR, ByRef r, ByRef g, ByRef b)
r = Color And (Not &HFFFFFF00)
g = (Color And (Not &HFFFF00FF)) &H100&
b = (Color And (Not &HFF00FFFF)) &HFFFF&
End Sub
Â
Function Module(X, Y, z)
' Returns the module of a 3D vector
Module = Sqr(X * X + Y * Y + z * z)
End Function
Â
Function Arg(xa, ya)
'Returns the argument (in radians) of a point in the (x,y) plan
Â
If xa = 0 And ya = 0 Then Arg = 0: Exit Function
If xa = 0 And ya >= 0 Then Arg = pi / 2: Exit Function
If ya = 0 And xa < 0 Then Arg = pi: Exit Function
If xa = 0 And ya < 0 Then Arg = -pi / 2: Exit Function
Â
If xa > 0 Then Arg = Atn(ya / xa): Exit Function
Â
If xa < 0 And ya >= 0 Then Arg = pi – Atn(-ya / xa)
If xa < 0 And ya < 0 Then Arg = -pi + Atn(-ya / -xa)
Â
End Function
Â
Best of Luck
Suominen Ross