Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleConvert R, G, and B values into Visual Basic and Web hex colors
KeywordsWeb colors, Web palette, RGB, hex, hexadecimal
CategoriesUtilities, 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
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated