Okay guys, this is it :) Plain and simple
The following code converts a Decimal Value to a Hexadecimal value, then takes the 3 RGB elements of the Hex number and converts them back into their 8-bit integers. It's not hard, 5 easy lines :)
Dim HexadecimalValue As String 'This will store the Hexadecimal Value as a string
Public Sub Decimal_to_RGB (DecimalValue As Long)
'the following lines all work out the decimal value from the Hexadecimal Value the
Dim RedValue As Integer 'This will store the integer Red value (value of 0 to 255)
Dim GreenValue As Integer 'This will store the integer Greenvalue (value of 0 to 255)
Dim BlueValue As Integer 'This will store the integer Blue value (value of 0 to 255)'This line will convert a Long decimal to Hexadecimal
End Sub
HexadecimalValue = Hex(Val(DecimalValue))
If Len(Hexadecimal.Text) < 6 Then
'Give is 6 digits for easy RGB conversion.
End If
HexadecimalValue = String(6 - Len(HexadecimalValue), "0") + HexadecimalValue
'hex number is broken up as such: &H RR GG BB
'The first two characters correspond to the red value, if you read it as a String,
'and add "&H" to the beginning of it, when CLng converts it from a string into a
'number, it will see it as a hex number, not a decimal and thus, the red value is found
RedValue = CLng("&H" + Mid(HexadecimalValue, 1, 2))
'The second two characters correspond to the green value, characters 3 and 4.
GreenValue = CLng("&H" + Mid(HexadecimalValue, 3, 2))
'The next two characters correspond to the blue value, characters 5 and 6.
BlueValue = CLng("&H" + Mid(HexadecimalValue, 5, 2))
Tutorial by Steven Blom
Special thanks to:
Chris, KoPP3x, Martin on Lucky's VB Gaming Message Board
(I remembered your discussion, but I didn't refer to it to write this.)