Question Hexadecimal Irritation (1 Viewer)

Steve R.

Retired
Local time
Today, 07:19
Joined
Jul 5, 2006
Messages
4,699
Any known reason why Access 2007 went from decimal numbers to hexadecimal numbers for defining colors in a form's property sheet?

I've learned to adapt, but I am wondering why this was done.
 

Atomic Shrimp

Humanoid lifeform
Local time
Today, 12:19
Joined
Jun 16, 2000
Messages
1,954
Maybe because they're so common elsewhere - in graphics packages, on the web, etc - everyone seems to use hex triplets.

Probably also because with an RGB colour value expressed in decimal, there is no fixed relationship between the digits and the component colours.
 

Banana

split with a cherry atop.
Local time
Today, 04:19
Joined
Sep 1, 2005
Messages
6,318
Actually, decimal numbers are representative of hexadecimal numbers, though it may seem that there's no relationship. However I would say using hexadecimal is more intuitive than decimal.

Consider:

Black
Code:
Decimal: 0
Hex: 0x00
Binary: 00000000 00000000 00000000 00000000

White
Code:
Decimal: 16777215
Hex: 0xFFFFFF
Binary: 00000000 11111111 11111111 11111111

Red
Code:
Decimal: 255
Hex: 0xFF
Binary: 00000000 00000000 00000000 11111111

Green
Code:
Decimal: 65280
Hex: 0xFF00
Binary: 00000000 00000000 11111111 00000000

Blue
Code:
Decimal: 16711680
Hex: 0xFF0000
Binary: 00000000 11111111 00000000 00000000

As you can see the rightmost three bytes correspond to each primary color, so you only need to know what hexadecimal values to gauge the intensity of color are, but it's not as easy with the decimal because it's not immediately obvious which number goes in which binary equivalent while hexadecimal is almost one to one (actually two nibbles to one byte), so it's easier to read a hexadecimal value.

Did that help?
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 12:19
Joined
Sep 12, 2006
Messages
15,660
note that there are also some constants for common colours

vbred, vbblue etc


since a colour is defined as rgb mix each of which is in the range (0-255) or in hex (0-FF)
it probably makes more sense to define them in that way.

you can always use hex function (eg hex(80) ) if you want to use integers

the longint colour numbers you see in property sheets are meaningless to all intents. (is A2007 different in this respect)
 

Atomic Shrimp

Humanoid lifeform
Local time
Today, 12:19
Joined
Jun 16, 2000
Messages
1,954
Actually, decimal numbers are representative of hexadecimal numbers, though it may seem that there's no relationship.
Yes, but what I meant is that there is no consistent relationship between specific digits and the component colours. (as you in fact went on to explain)
 

Banana

split with a cherry atop.
Local time
Today, 04:19
Joined
Sep 1, 2005
Messages
6,318
Actually, there is a consistent relationship, just not immediately obvious. For example, suppose we wanted yellow. We only need to add red and green, right?

65280 + 255 = 65535, which works out in hex/binary as thus:
Code:
Hex: 0xFFFF
Binary: 00000000 00000000 11111111 11111111

Likewise, to get cyan, we add together blue and green. So that's 16711680 + 65280 = 16776960
Code:
Hex: 0xFFFF00
Binary: 00000000 11111111 11111111 00000000

If you consider that white is 16777215, and subtract from 16776960, we are left with 255, which is exactly the missing red component. Likewise, subtracting 16777215 - 65535 = 16711680 which is exactly the blue.

So, it's really consistent but not that obvious because of, for a better of description, we "increment" the color component. As shown before, the red, green and blue corresponds to a specific byte within the 4-byte integer, so there's a range of values for which each byte applies (e.g. 0-255 for red, while 256 would give us a faint hint of green buried in blackness, but we're starting the red component all over and when we hit the 512th mark, we're now two shade of green in black again (511th would give us strong red with a tinge of green), then we run through the red component all again.
 

Atomic Shrimp

Humanoid lifeform
Local time
Today, 12:19
Joined
Jun 16, 2000
Messages
1,954
That's a consistent relationship with the value not specific digits in the decimal expression of that value.
 

Banana

split with a cherry atop.
Local time
Today, 04:19
Joined
Sep 1, 2005
Messages
6,318
Ah, I now see what you were trying to get. Yes, I think we're in agreement that it's not really easy to work with decimal numbers; one would have to remember to add 1 for more red, 256 for more green, 65536 for more blue whereas hexadecimal is much more straightforward.
 

Steve R.

Retired
Local time
Today, 07:19
Joined
Jul 5, 2006
Messages
4,699
Very informative and interesting. I was not aware that Hexadecimal numbers provided one with insight into the "structure" of the color.
 

Steve R.

Retired
Local time
Today, 07:19
Joined
Jul 5, 2006
Messages
4,699
Looks like I didn't look deeply enough into the issue of how Access sets its form color properties.

I set a form's back color property (in design view) to "#C96121". I assumed that was hexadecimal number, but I was wrong. When I did a debug.print, the decimal value turned out to be "1922479". Then when I ran a decimal to hex conversion the result was "1D55AF".

So what type of number is "#C96121" in the detail property sheet (design view)?
 

Simon_MT

Registered User.
Local time
Today, 12:19
Joined
Feb 26, 2007
Messages
2,177
The reason for the change is Access 2010 is reputedly going to be browser friendly. The other preparatory changes for web ready Access are Margin and Padding to name two.

Simon
 

Banana

split with a cherry atop.
Local time
Today, 04:19
Joined
Sep 1, 2005
Messages
6,318
Looks like I didn't look deeply enough into the issue of how Access sets its form color properties.

I set a form's back color property (in design view) to "#C96121". I assumed that was hexadecimal number, but I was wrong. When I did a debug.print, the decimal value turned out to be "1922479". Then when I ran a decimal to hex conversion the result was "1D55AF".

So what type of number is "#C96121" in the detail property sheet (design view)?

You're running into problem of looking at wrong ends.

I can't recall which is which, but I believe HTML coding scheme is little-endian while the traditional color coding scheme is big-endian. (or other way, but I am pretty sure the endianness is different)
 

Steve R.

Retired
Local time
Today, 07:19
Joined
Jul 5, 2006
Messages
4,699
Thanks Simon and Banana. It's just irritating to have to use debug.print to get the decimal value of a forms back color. Technically, when I set the back color in the form's design view, I don't need to mess with VBA in actually setting the back color. This issue temporarily stuck-out when we upgraded to Access 2007 and I was able to work around it. I am just trying to get an understanding of why Microsoft felt it was necessary to modify how colors were designated.
 

Access Hero

Registered User.
Local time
Today, 06:19
Joined
Oct 29, 2008
Messages
96
Odd, it seems like this is the only thing MS did right in Access 2007. Having an RGB color in decimal never made any sense to me. Now you can tell what color something is just by looking at the number...much better.
 

Steve R.

Retired
Local time
Today, 07:19
Joined
Jul 5, 2006
Messages
4,699
The remaining question then is how to convert the HTML color code in the form's design view so that VBA can use it. After doing some experimenting here is the VBA function that I came up with.

Code:
Me.Detail.BackColor = HTMLConvert("#D8B190")

Code:
Public Function HTMLConvert(strHTML As String) As Long
    Rem converts a HTML color code number such as #D8B190 to an RGB value.
    HTMLConvert = RGB(CInt("&H" & Mid(strHTML, 2, 2)), CInt("&H" & Mid(strHTML, 4, 2)), CInt("&H" & Mid(strHTML, 6, 2)))
End Function

Thanks to everyone for helping me to understand this format. Additional thanks go out to other posts by BubuX and Kreangsak
 

Users who are viewing this thread

Top Bottom