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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Color Conversion vb decimal to RRGGBB

Status
Not open for further replies.

sodakotahusker

Programmer
Mar 15, 2001
601
I want to convert a vb color from decimal to the hex RRGGBB format. I have it working going the other direction but the algorithm I came up with for going from (eg) 1654433 to a4bbc9 is not working right. Anybody know the correct formula for this conversion??
 
RGB in hex is actually BBGGRR.
Try this to see where they go.
Code:
Dim lngColor
lngColor = RGB(1,0,0)
Debug.Print "RED  =" & Cstr(lngColor) 
lngColor = RGB(0,1,0)
Debug.Print "GREEN=" & Cstr(lngColor) 
lngColor = RGB(0,0,1)
Debug.Print "BLUE =" & Cstr(lngColor)
  [URL unfurl="true"]WWW.VBCompare.Com[/URL]
 
So if I divide the decimal number by 65536 - I'd get the blue value - subtract the combo(blue value * 65536) from the total - and then divide by 256 to get the green value - subtract the green factor and what is left is my red value. Got it!!! Thanks!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top