&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

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

Who is Participating?
Gustav BrockConnect With a Mentor CIOCommented:
You can use:

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

Dave BaldwinConnect With a Mentor Fixer 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.
BitsqueezerConnect With a Mentor Commented:

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


Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

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! = )
Gustav BrockCIOCommented:
You are wrong about that. A constant is - eh - constant.

developingprogrammerAuthor Commented:
Oops you are right gustav!! Silly me!! Haha = )) thanks for clearing up my head!! = ))
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.