Skip to content


How to convert from VB color format to the HTML format

Today I needed a way to convert from VB color format to the hexadecimal HTML format so after 5-10 minutes I came with the code & post below.

Visual Basic stores the color data in the following format : 00BBGGRR so the next logical step to extract the information in the format we need ( #RRGGBB ) is to inverse the red component with the blue component.Simple, right? :)

Visual Basic [Show Plain Code]:
  1. Function VB2HTMLColor(color As Long) As String
  2.     Dim aux As String
  3.     aux = Right("00000" & Hex(color), 6)
  4.     VB2HTMLColor = "#" & Right(aux, 2) & Mid(aux, 3, 2) & Left(aux, 2)
  5. End Function

Posted in Visual Basic 6 Tips & Tricks.


One Response

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Adam Komar says

    Works perfectly. Thanks much.



Some HTML is OK

or, reply to this post via trackback.


Get Adobe Flash playerPlugin by wpburn.com wordpress themes