Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting VB colors to web-friendly HEX code

Status
Not open for further replies.

AncientTiger

Programmer
Jul 5, 2001
238
US
I've searched and searched today and I've seen a LOT of examples on how to convert HEX to VB RGB, but I'm not finding any advise on the reverse. Wondering if it's even possible

Here's what I'm trying to do: I have a form with a label and a commondialog control for selecting/changing the backcolor on the label. I'm wanting to take that chosen backcolor, which comes out as a decimal value, and convert that to a HTML HEX color value.

So, for the color VBGreen, I get this:
VB COLOR VALUE: 65280
AFTER CONVERSION USING THE HEX COMMAND: FF00 ' ( EXA: THISCOLOR= HEX(MYVBCOLOR) )

Now, that's NOT a valid HTML color value. If plugged that into a webpage, it would be pure RED, not green.

Any suggestions?

------------------------------------
[yinyang] Over 30 years of programming, and still learning every day! [yinyang]
 
It's a quirk of HTML - when specifying colours in Hex it requires all three RGB bytes, even if they are 0.

So FF00 actually needs to be 00FF00
 
It helps if the user chooses a primary color, but when dealing with 16 million possibilities, it get's a little but into a gray area there.

Appreciate the suggestion though :)


------------------------------------
[yinyang] Over 30 years of programming, and still learning every day! [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top