ThreadBoard ArchivesSite FeaturesActiveworlds SupportHistoric Archives |
[VB] Quick Question regarding color values... (Sdk)
[VB] Quick Question regarding color values... // SdkrobbieAug 15, 2002, 7:52pm
You can convert a RGB value into a Hex color value in VB using the rgb()
command. How do you convert a hex color value back into a RGB value? -Robbie grimbleAug 15, 2002, 9:05pm
Parting gesture from me this ... a little piece of safe demo code. Note the
order of the red, green and blue components of the RGB value is not a mistake ... its held as BGR in the long. If you want the values as individual hex strings, obviously just use left, right and mid to separate the string. The &H tells VB the string in the Val command is a hex string, otherwise 20 will come out as 14 (20 decimal = hex 14), so its important. Dim rgbColor As Long Dim hexColor As String Dim rgbR As Long Dim rgbG As Long Dim rgbB As Long 'Create the test RGB color value rgbColor = RGB(10, 20, 30) 'Ensure the value is formatted as 6 bytes (ease of use) hexColor = Right("000000" & Hex(rgbColor), 6) 'Extract the R, G and B components rgbR = Val("&H" & Right(hexColor, 2)) rgbG = Val("&H" & Mid(hexColor, 3, 2)) rgbB = Val("&H" & Left(hexColor, 2)) Debug.Print rgbR, rgbG, rgbB I think that's what you meant. Grims [View Quote] |