Any clue how to get the three R-G-B values from the long RGB() outputs?
Never mind I figured it out and made my own function for it:
Public Function LongToRGBString(ByVal Color As Long) As String
Dim HexColor As String
HexColor = CStr(Hex(Color))
If (HexColor <> 0) Then
LongToRGBString = CByte("&H" & Right$(HexColor, 2)) & ", " & CByte("&H" & Mid$(HexColor, 3, 2)) & ", " & CByte("&H" & Left$(HexColor, 2))
Else
LongToRGBString = "255, 255, 255"
End If
End Function
Yeah, you figured it out. In &HFF5522, &H = long, hex; FF = Red; 55 = Green; 22 = Blue.
Quote from: Joe on November 22, 2005, 06:57 AM
Yeah, you figured it out. In &HFF5522, &H = long, hex; FF = Red; 55 = Green; 22 = Blue.
&H doesn't indicate that it's a Long variable, only that the following value is encoded in hex.
It bugged out a bit so I googled a bit and found something much more efficient and stable:
Public Function ColorCodeToRGB(lColorCode As Long) As String
Dim lColor As Long
lColor = lColorCode 'work long
iRed = lColor Mod &H100 'get red component
lColor = lColor \ &H100 'divide
iGreen = lColor Mod &H100 'get green component
lColor = lColor \ &H100 'divide
iBlue = lColor Mod &H100 'get blue component
ColorCodeToRGB = iRed & ", " & iGreen & ", " & iBlue
End Function
Quote from: MyndFyre on November 22, 2005, 03:39 PM
Quote from: Joe on November 22, 2005, 06:57 AM
Yeah, you figured it out. In &HFF5522, &H = long, hex; FF = Red; 55 = Green; 22 = Blue.
&H doesn't indicate that it's a Long variable, only that the following value is encoded in hex.
& represents long.
Dim Val&
Dim Val as Long
Dim Val$
Dim Val as String
Dim Val#
Dim Val as Double
Etc.
I think it's a hex based representation of a long value which is converted later during storage or w/e.
Quote from: Joe on November 23, 2005, 09:53 PM
Quote from: MyndFyre on November 22, 2005, 03:39 PM
Quote from: Joe on November 22, 2005, 06:57 AM
Yeah, you figured it out. In &HFF5522, &H = long, hex; FF = Red; 55 = Green; 22 = Blue.
&H doesn't indicate that it's a Long variable, only that the following value is encoded in hex.
& represents long.
Dim Val&
Dim Val as Long
Dim Val$
Dim Val as String
Dim Val#
Dim Val as Double
Etc.
&H means "base 16", just like &O means "base 8". Non-base 10 values default to Long anyway, unless assigned to an Integer. Bad Joe.
Damn misleading language. & still means long, usually. =p
EDIT -
My bad, I guess its stored in Blue-Green-Red instead of Red-Green-Blue.
Option Explicit
Public Sub Main()
Dim m_lRGB As Long
Dim m_bRed1 As Byte, m_bGreen1 As Byte, m_bBlue1 As Byte
Dim m_bRed2 As Byte, m_bGreen2 As Byte, m_bBlue2 As Byte
m_bRed1 = 1
m_bGreen1 = 2
m_bBlue1 = 3
m_lRGB = RGB(m_bRed1, m_bGreen1, m_bBlue1)
Call ReverseRGB(m_lRGB, m_bRed2, m_bGreen2, m_bBlue2)
Call MsgBox("RGB(" & m_bRed1 & ", " & m_bGreen1 & ", " & m_bBlue1 & ")")
Call MsgBox("RGB(" & m_bRed2 & ", " & m_bGreen2 & ", " & m_bBlue2 & ")")
End Sub
Public Sub ReverseRGB(ByVal p_lRGB As Long, ByRef r_bRed As Byte, ByRef r_bGreen As Byte, ByRef r_bBlue As Byte)
r_bBlue = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 1, 2))
r_bGreen = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 3, 2))
r_bRed = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 5, 2))
End Sub
Quote from: Joe on November 26, 2005, 12:48 AM
Damn misleading language. & still means long, usually. =p
EDIT -
My bad, I guess its stored in Blue-Green-Red instead of Red-Green-Blue.
Option Explicit
Public Sub Main()
Dim m_lRGB As Long
Dim m_bRed1 As Byte, m_bGreen1 As Byte, m_bBlue1 As Byte
Dim m_bRed2 As Byte, m_bGreen2 As Byte, m_bBlue2 As Byte
m_bRed1 = 1
m_bGreen1 = 2
m_bBlue1 = 3
m_lRGB = RGB(m_bRed1, m_bGreen1, m_bBlue1)
Call ReverseRGB(m_lRGB, m_bRed2, m_bGreen2, m_bBlue2)
Call MsgBox("RGB(" & m_bRed1 & ", " & m_bGreen1 & ", " & m_bBlue1 & ")")
Call MsgBox("RGB(" & m_bRed2 & ", " & m_bGreen2 & ", " & m_bBlue2 & ")")
End Sub
Public Sub ReverseRGB(ByVal p_lRGB As Long, ByRef r_bRed As Byte, ByRef r_bGreen As Byte, ByRef r_bBlue As Byte)
r_bBlue = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 1, 2))
r_bGreen = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 3, 2))
r_bRed = Val("&H" & Mid(Right("000000" & Hex(p_lRGB), 6), 5, 2))
End Sub
No I believe it's stored as R-G-B, the code I provided above works fine.
Yes, it extracts the value red, which is at the end of it. Then it divides by 0x100, taking the next byte one value to the right. Then it removes blue, which was in the middle. Then it divides by 0x100 again. Then it finally extracts blue, which was at the high end of it. Its extracting it in the order R G B, but its doing it backwards, so its B G R.
Why don't you just use code already given in vb6...
Form1.BackColor = RGB(R, G, B)
R = Red as Integer
G = Green as Integer
B = Blue as Integer
Quote from: iNsaNe on March 05, 2006, 04:46 PM
Why don't you just use code already given in vb6...
Form1.BackColor = RGB(R, G, B)
R = Red as Integer
G = Green as Integer
B = Blue as Integer
Read the topic title, RGB
revert. Meaning: he wants to get the red, green, blue values from a value already assigned from RGB()
Why not Just convert the decimal to hex using the Hex() function? Then you can split it up into pairs... (remember to add trailing zeroes first)...
Jesus your sig laggs... when i scoll past it..