|
|
Title | Convert R, G, and B values into Visual Basic and Web hex colors |
Keywords | Web colors, Web palette, RGB, hex, hexadecimal |
Categories | Utilities, Graphics |
|
|
The Visual Basic color format is BBGGRR. The Web format is RRGGBB. Function VBHexColor converts R, G, and B values into a VB-style hex color value. Function WebHexColor converts R, G, and B values into a Web-style hex color value.
|
|
' VB color: BBGGRR.
Private Function VBHexColor(ByVal r As Long, ByVal g As _
Long, ByVal b As Long) As String
Dim clr As OLE_COLOR
Dim txt As String
clr = r + 256 * (g + 256 * b)
txt = Hex$(clr)
If Len(txt) < 6 Then txt = "0" & txt
VBHexColor = txt
End Function
' Web color: RRGGBB.
Private Function WebHexColor(ByVal r As Long, ByVal g As _
Long, ByVal b As Long) As String
Dim clr As OLE_COLOR
clr = b + 256 * (g + 256 * r)
WebHexColor = Right$("000000" & Hex$(clr), 6)
End Function
|
|
|
|
|
|