How would I convert something like &HFFFFFF into RGB(255, 255, 255)?
Printable View
How would I convert something like &HFFFFFF into RGB(255, 255, 255)?
Dreamlax, may be you can use the CDec function as below:
:)Code:Private Sub Form_Load()
Dim R%, G%, B%
Dim HexColorCode$
HexColorCode = "&HFFFFFF"
'Assume Hex Color Code = &HFFFFFF
R = CDec("&H" & Mid(HexColorCode, 3, 2))
G = CDec("&H" & Mid(HexColorCode, 5, 2))
B = CDec("&H" & Mid(HexColorCode, 7, 2))
MsgBox "&HFFFFFF = RGB(" & R & ", " & G & ", " & B & ")"
End Sub
That won't work if the colour is black because black is &H0 not &H000000.
it would be pretty complicated...
but the concept of hex is easy
I am only posting for the blue, because it takes along time to type it up, and takes up too much space, but you can gain the general concept by this table....
http://denniswrenn.virtualave.net/RGBHEX.htm
[Edited by denniswrenn on 05-27-2000 at 11:13 PM]
Hi Dreamlax, This more flexible & resolve your problem,
:)Code:Option Explicit
Private Sub Form_Load()
Dim R%, G%, B%
Dim HexColorCode$
'Assume Hex Color Code = &HFFFFFF
HexColorCode = "&H0"
R = GetRGB(CDec(HexColorCode), 1)
G = GetRGB(CDec(HexColorCode), 2)
B = GetRGB(CDec(HexColorCode), 3)
MsgBox HexColorCode & " = RGB(" & R & ", " & G & ", " & B & ")"
End Sub
Function GetRGB(RGBval As Long, Num As Integer) As Integer
' RGB color value as Long, and component number as integer
' that represents the component color to return (1=red,
' 2=green, 3=blue).
' Check if Num, RGBval are valid.
If Num > 0 And Num < 4 And RGBval > -1 And RGBval < 16777216 Then
GetRGB = RGBval \ 256 ^ (Num - 1) And 255
Else
' Return True (-1) if Num or RGBval are invalid.
GetRGB = 0
End If
End Function
Just don't get upset but making all the fancy rgb functions
will just drain your performance. The fastest way is always
is the straightest
Code:R=color mod 256
G=int(color/256) mod 256
B=int(color/&H10000)