&H and constants

hey guys i want to use a constant t orepresent my hex value. essentially i want to do something like the below.

how do i do it in the proper way? using constants to represent hex? thanks guys!!

Public Const chexDisabledBackColour     As String = "D3D3D3"
Public Const chexEnabledBackColour      As String = "FFFFFF"

Me.txtReason.BackColor = &HmodGenericResources.chexDisabledBackColour

Question
is this the only way? how do yall usually do it when you wanna use constants and hexadecimals?

     Function HexToLong(ByVal sHex As String) As Long
        HexToLong = Val("&H" & sHex & "&")
      End Function

http://support.microsoft.com/kb/161304
developingprogrammerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
In some important ways, color codes for displays and the web are not normal numbers and trying to represent them as 'Longs' will cause you problems.  First, converting the colors strings to numbers will strip any leading zeros which are required as place holders.  The code for 'blue' is #0000FF.  If you strip the leading zeros, you no longer have a valid color code.  This page has a description of the correct representation of color codes: http://www.w3schools.com/html/html_colors.asp  Note that all my programs including Photoshop use these same set of codes for RGB colors.
0
BitsqueezerCommented:
Hi,

why do a conversion where it is not needed?

I first try to use the available vb constants if possible (like "vbRed"). If not, I use the RGB function to calculate the result long value and copy that into a long constant and write the values of the RGB function as command behind, like:
Public Const cMyGrey As Long = 6579300   'RGB(100,100,100)

Open in new window


Cheers,

Christian
0
Gustav BrockCIOCommented:
You can use:

Public Const chexDisabledBackColour     As Long = &HD3D3D3
Public Const chexEnabledBackColour      As Long = &HFFFFFF

/gustav
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

developingprogrammerAuthor Commented:
thanks Dave! i didn't know that previously! very good point you brought up!! = ))

thanks Christian! i didn't think of the - RGB function previously

thanks gustav! that was what i was looking for - for learning purposes. but i think i should just store it as a long next time cause the &H will cause a recalculation each time i use the constant if i'm not wrong! = )
0
Gustav BrockCIOCommented:
You are wrong about that. A constant is - eh - constant.

/gustav
0
developingprogrammerAuthor Commented:
Oops you are right gustav!! Silly me!! Haha = )) thanks for clearing up my head!! = ))
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.