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

How to retrieve the RGB from a HEX number?

Status
Not open for further replies.

Lbob

Programmer
May 23, 2003
157
0
0
GB
Hi

I'm trying to work out what the RGB of H8000000F is? Is there a way of doing it?

Cheers
Lbob
 
That particular color is the default grey color. According to the help file, that color is one of the system colors and is out of the range of RGB color.

VB Helpfiles said:
The valid range for a normal RGB color is 0 to 16,777,215 (&HFFFFFF). The high byte of a number in this range equals 0; the lower 3 bytes, from least to most significant byte, determine the amount of red, green, and blue, respectively. The red, green, and blue components are each represented by a number between 0 and 255 (&HFF). If the high byte isn't 0, Visual Basic uses the system colors, as defined in the user's Control Panel settings and by constants listed in the Visual Basic (VB) object library in the Object Browser.

I know this doesnt really answer the question but I'm hoping maybe it will trigger somebody's memory of a solution to this issue.

 
&H8000000F is not an RGB color triplet, but it is an OLE_COLOR value which has a special meaning.

VB allows you to express colors in two ways.
1. Normal RGB color. (COLORREF)
2. System defined colors. (OLE_COLOR)

In first case, the actual color value is stored in a 4-byte variable. The lower three bytes store the R-G-B component and 4th or most significant byte is always zero.

If the most significant byte is non-zero than it falls in the second category and this color value needs to be translated to an RGB value if you want to manipulate it yourself.

&H8000000F is actually the vb3DFace color constant defined in Enum SystemColorConstants. You can see other system color constants in Object Browser. It means that if you select or specify this color value, the object automatically assumes the color of 3D objects defined according to current theme settings.

All VB functions and properties like PSet, Circle, ForeColor, BackColor support these special color constants and you don't need to convert these special color constants to RGB color value before passing to these function.

Conversion might be needed if you are, for example, passing the color value to an API function which mostly work with RGB triplet value.

A system color constant like this can be converted to an RGB triplet using GetSysColor or OleTranslateColor function.

See thread222-672031 for more details.
 
Since the value starts with H80, this indicates a system color, which coule be different from computer to computer. If the color starts with H00 then it is a 'hard coded color'. The digits that follow represent the RGB color.

So, H0080C0FF...

FF = Red
C0 = Green
80 = Blue

To convert this to a long...
MsgBox RGB(&HFF, &HC0, &H80)

Since your color value starts with H80, and this is a named system color constant, you can see what this maps to by doing this...

Open VB
Press F2 (to show the object browser)
In the classes section, scroll down to SystemColorConstants

On the right, you will see the members of 'SystemColorConstants'

Click on vb3DFace and you will see:
[tt][blue]Const vb3DFace = -2147483633 (&H8000000F)[/blue][/tt]

So, this is a named color in control panel. Honestly, I don't know how to get the actual color for this. Sorry.




-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
actually there are procedures posted in these (Tek-Tips) fora which do hte various conversions (long to hex; long to rgb;) and, of course - the intrinsic function lng = RGB(rbyte, gbyte, bbyte) will return the long which represents the color.

I believe a search (or and advanced one) with the key work "RGB" will turn up enough references to lead to the actual procedures.




MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top