[AccessD] Color Number Format

Rocky Smolin rockysmolin at bchacc.com
Sun Apr 9 15:24:01 CDT 2017


My pleasure.  Even a blind squirrel finds a nut once in a while. :)

R


-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
Steve Schapel
Sent: Sunday, April 09, 2017 11:57 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Color Number Format

LOL.  I thought you already knew that, Rocky, in fact I'm pretty sure I have
seen you say as much before.

Having said that, I have also learnt something from this thread, I wasn't
aware of that conundrum.  So thanks a lot.

Regards
Steve

-----Original Message-----
From: Rocky Smolin
Sent: Monday, April 10, 2017 3:10 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Color Number Format

Resistance is futile? :)

r

-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
Gustav Brock
Sent: Sunday, April 09, 2017 7:35 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Color Number Format

Hi Rocky

I don't think that property is for you to change.
And the #000000 format is a CSS standard and used all over (outside VBA), so
you better assimilate it.

/gustav
________________________________________
Fra: AccessD <accessd-bounces at databaseadvisors.com> på vegne af Rocky Smolin
<rockysmolin at bchacc.com>
Sendt: 9. april 2017 16:18:54
Til: 'Access Developers discussion and problem solving'
Emne: Re: [AccessD] Color Number Format

Gustav:

So I discovered by accident (or brilliant deduction) last night that the RGB
representation in the property sheet with # was the reverse of the &H
representation in VBA.

Why would they do that?  Some programmer's sense of humor?

I think I'm going to switch to a simpler language like Mandarin or ancient
Aramaic. :)

But your code goes in my library.  Somehow I managed 20 years of Access
development without having to fiddle with this. But in 2010 because the
property sheet is in that #nnnnnn format I probably will again.

Is there no preference switch somewhere to have access display decimal in
the property sheet like good old Access 2003?

Thank you.

Rocky


-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
Gustav Brock
Sent: Sunday, April 09, 2017 2:43 AM
To: 'Access Developers discussion and problem solving'; 'Off Topic'
Subject: Re: [AccessD] Color Number Format

Hi Rocky

The #112233 format is still in RGB sequence but it's a hex representation,
not the hex value.

The hex value will be &H332211 because Red is the "small" component.

Recently, I had a lot of similar conversions to do and made these small
functions to minimise the dull work:

<code>
' Calculate discrete RGB colours from a composite colour value and ' return
one component.
' Also, by reference, return all components.
'
' Examples:
'   Simple print of the components:
'
'   SomeColor = 813466
'   RGBComponent SomeColor
'   ' Debug Print:
'   ' 154           105           12
'
'   Get one component from a colour value:
'
'   Dim SomeColor   As Long
'   Dim Green       As Integer
'   SomeColor = 13466
'   Green = RGBComponent(SomeColor, vbGreen)
'   ' Green ->  52
'
'   Get all components from a colour value:
'
'   Dim SomeColor   As Long
'   Dim Red         As Integer
'   Dim Green       As Integer
'   Dim Blue        As Integer
'   SomeColor = 813466
'   RGBComponent SomeColor, , Red, Green, Blue
'   ' Red   -> 154
'   ' Green -> 105
'   ' Green ->  12
'
' 2017-03-26. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function RGBComponent( _
    ByVal RGB As Long, _
    Optional ByVal Component As Long, _
    Optional ByRef Red As Integer, _
    Optional ByRef Green As Integer, _
    Optional ByRef Blue As Integer) _
    As Integer

    Dim Color   As Long

    If RGB <= 0 Then
        ' Return Black.
        Red = 0
        Green = 0
        Blue = 0
    Else
        ' Dissolve composite RGB into discrete colours.
        Red = RGB And vbRed
        Green = (RGB And vbGreen) / &H100
        Blue = (RGB And vbBlue) / &H10000
        ' Return chosen colour component.
        Select Case Component
            Case vbRed
                Color = Red
            Case vbGreen
                Color = Green
            Case vbBlue
                Color = Blue
            Case Else
                Color = vbBlack
        End Select
    End If

    Debug.Print Red, Green, Blue

    RGBComponent = Color

End Function


' Returns the numeric RGB value from an CSS RGB hex representation.
' Will accept strings with or without a leading octothorpe.
'
' Examples:
'   Color = RGBCompound("#9A690C")
'   ' Color = 813466
'   Color = RGBCompound("9A690C")
'   ' Color = 813466
'
' 2017-03-26. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function RGBCompound( _
    ByVal HexRGB As String) _
    As Long

    ' Format of RGB hex strings.
    Const RGBPrefix As String = "#"
    Const Length    As Integer = 6
    ' Format of Hex values.
    Const HexPrefix As String = "&H"

    Dim Start       As Integer
    Dim Color       As Long

    If Mid(HexRGB, 1, 1) = RGBPrefix Then
        Start = 1
    End If
    If Len(HexRGB) = Start + Length Then
        Color = RGB( _
            HexPrefix & Mid(HexRGB, Start + 1, 2), _
            HexPrefix & Mid(HexRGB, Start + 3, 2), _
            HexPrefix & Mid(HexRGB, Start + 5, 2))
    End If

    RGBCompound = Color

End Function


' Returns the CSS hex representation of a decimal RGB value ' with or
without a leading octothorpe.
'
' Example:
'   CSSValue = RGBHex(813466)
'   ' CSSValue = "#9A690C"
'   CSSValue = RGBHex(813466, True)
'   ' CSSValue = "9A690C"
'
' 2017-03-26. Gustav Brock, Cactus Data ApS, CPH.
'
Public Function RGBHex( _
    ByVal Color As Long, _
    Optional ByVal NoPrefix As Boolean) _
    As String

    ' Format of RGB hex strings.
    Const RGBPrefix As String = "#"

    Dim Red     As Integer
    Dim Green   As Integer
    Dim Blue    As Integer
    Dim HexRGB  As String

    RGBComponent Color, , Red, Green, Blue

    If Not NoPrefix Then
        ' Set prefix.
        HexRGB = RGBPrefix
    End If
    ' Assemble compound string with leading zeroes for small values.
    HexRGB = HexRGB & _
        Right("0" & Hex(Red), 2) & _
        Right("0" & Hex(Green), 2) & _
        Right("0" & Hex(Blue), 2)

    RGBHex = HexRGB

End Function
</code>

/gustav

________________________________________
Fra: AccessD <accessd-bounces at databaseadvisors.com> på vegne af Rocky Smolin
<rockysmolin at bchacc.com>
Sendt: 9. april 2017 06:18:19
Til: 'Access Developers discussion and problem solving'; 'Off Topic'
Emne: [AccessD] Color Number Format

Dear List(s):

In A2003 colors in the property sheet were entered in decimal by default
(Back Color, Border Color, etc.)

In A2010 the default is Hex (#nnnnnn).

I would like it to default to decimal but can't find where that switch is.

Does anybody know?

MTIA
Rocky Smolin

Beach Access Software

760-683-5777

<http://www.bchacc.com> www.bchacc.com

<http://www.e-z-mrp.com> www.e-z-mrp.com

Skype: rocky.smolin
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com


--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com 

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list