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 HTML colors to and from Visual Basic colors
KeywordsWeb color, HTML color, color, VB color
CategoriesGraphics, Utilities
 
By Kreangsak.

HTML colors are written in the format RRGGBB. Visual Basic colors are stored with the blue value in the most significant bits: BBGGRR. The functions in this program use InStr to rearrange the hexadecimal digits to convert from one system to the other.

 
Private Function CvtColorVB2Web(colorcode As String) As _
    String
Dim vcolor
    vcolor = Hex(Val(colorcode))
    If Len(vcolor) < 6 Then
       vcolor = String(6 - Len(vcolor), "0") & vcolor
    End If
    CvtColorVB2Web = Mid(vcolor, 5, 2) & Mid(vcolor, 3, 2) _
        & Mid(vcolor, 1, 2)
End Function

Private Function CvtColorWeb2VB(colorcode As String) As _
    String
    If Len(colorcode) < 6 Then
       colorcode = colorcode & String(6 - Len(colorcode), _
           "0")
    End If
    CvtColorWeb2VB = "&H" & Mid(colorcode, 5, 2) & _
        Mid(colorcode, 3, 2) & Mid(colorcode, 1, 2)
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated