Thread

[VB] Quick Question regarding color values... (Sdk)

[VB] Quick Question regarding color values... // Sdk

1  |  

robbie

Aug 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

strike rapier

Aug 15, 2002, 8:15pm
StrColor = Hex(R) & Hex(G) & Hex(B)?
[View Quote]

grimble

Aug 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]

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn