Terms of Agreement:
By using this article, you agree to the following terms...
You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
Public Function hextorgb(hexcolor As String)
'input format = #FFCC00
Dim r, g, b As Byte
r = CByte("&H" & Mid(hexcolor, 2, 2))
g = CByte("&H" & Mid(hexcolor, 4, 2))
b = CByte("&H" & Mid(hexcolor, 6, 2))
hextorgb = r & "," & g & "," & b
End Function
Public Function rgbtohex(r As Byte, g As Byte, b As Byte)
'input format = 255,255,255
'get the r value
If r < 16 Then
hex1 = 0 & Hex(r)
Else
hex1 = Hex(r)
End If
'get the g value
If r < 16 Then
hex2 = 0 & Hex(g)
Else
hex2 = Hex(g)
End If
'get the b value
If b < 16 Then
hex3 = 0 & Hex(b)
Else
hex3 = Hex(b)
End If
rgbtohex = "#" & hex1 & hex2 & hex3
End Function
Public Function rgbtocolor(r As Byte, g As Byte, b As Byte)
rgbtocolor = r + (g * 256) + (b * 65536)
End Function
Public Function colortorgb(color As Long)
Dim r, g, b As Byte
r = color And 255
g = (color \ 256) And 255
b = (color \ 65536) And 255
colortorgb = r & "," & g & "," & b
End Function
My dear Pamela, Thank you so much for this submission, I was desperatly looking for a ColorToRGB translation. You have hepled me a lot :) 5 glbs for you! (If this comment was disrespectful, please report it.)
2/25/2004 3:36:19 AM:
- (If this comment was disrespectful, please report it.)
Gr8. but can you plz add explanation for all the weird numbers. we need to UNDERSTAND it not Copy+Paste it!!! (If this comment was disrespectful, please report it.)
ERROR!! this won't work! what if i do HexToRGB("#1F15C") HAH? (If this comment was disrespectful, please report it.)
11/12/2004 10:54:17 PM:
pamela 1 apluse, pamela 2 i salute you, pamela 3 plz help me find something about words number conversion like cheque, pamela 4 thanks man. (If this comment was disrespectful, please report it.)
11/19/2004 8:41:24 AM:
nice program and has good logic technique
(If this comment was disrespectful, please report it.)
3/23/2005 9:27:00 AM:
hi i don't know what text boxes or labels to add to the program and what names to call them... i tried making 2 textboxes... 1 called rgbtocolor and the other called colortorgb but no success can someone please tell me or send me a copy WITH the project! (If this comment was disrespectful, please report it.)
ok good (If this comment was disrespectful, please report it.)
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)