-
Html Hex to RGB
hi,
I have done a search but couldnt really find what i was looking for.
I have 3 horizontal scroll bars, which are R G B, you can make different colours with this and it will give you the html hex code for the colour, how can i make it so it can convert html hex to rgb, and set the scrool bars to the correct value ?
please help
thanks
-
use mid to break up the HTML hex string and use val to convert the 2-nibble hex vals to decimal for the scroll bars. When using val, you need to put &H in front of the 2-nibble hex, so if you have
8a, it needs to become val(&H8a)
-
um, can anyone help me a little more ?
-
Hope this will work
Public Function HEX2RGB(HexColorStr As String) As Long
RED_COLOR = CLng("&H" & Mid(HexColorStr, 1, 2)) '(CLng("&H" & HexColorStr) And &HFF0000) / &HFFFF
'mask 111111110000000000000000 and shift bits right
GREEN_COLOR = CLng("&H" & Mid(HexColorStr, 3, 2)) '(CLng("&H" & HexColorStr) And &HFF00) / &HFF
'mask 000000001111111100000000 and shift bits right
BLUE_COLOR = CLng("&H" & Mid(HexColorStr, 5, 2)) 'CLng("&H" & HexColorStr) And &HFF
'mask 000000000000000011111111 and shift bits right
HEX2RGB = RGB(RED_COLOR, GREEN_COLOR, BLUE_COLOR)
End Function
usage : HEX2RGB("C0FABC")