how does the "BackColor" Long Integer work?

Posted on 2006-04-03
Last Modified: 2008-02-26
white = 16777215
pink = 13027071
blue = 15977088

(or there abouts)

what i'm asking is, if i want to tweek the shade a little, what's the logic?

i thought it might be RRR GGG BBB but (besides there not being 9 digits) i've been playing with it, and i can't determine any rhyme to it.

for the points, please tell me what digits control what aspects of the color (or a good web site where this information can be found)


Question by:MacRena
    LVL 42

    Accepted Solution

    Here's the color constants (in hex) which I believe are additive.  

    vbRed         0x0000FF       Red
    vbGreen      0x00FF00       Green
    vbBlue        0xFF0000       Blue

    For example, to Yellow = Red + Green = 0x0000FF + 0x00FF00 = 0x00FFFF

    To get less red, subtract n *  (2 ^ 0)  where n = 1 to 255
    To get less green, subtract n * (2 ^ 8) where n = 1 to 255
    To get less blue, subtract n * (2 ^ 16) where n = 1 to 255
    LVL 58

    Assisted Solution

    If you want to tweak the colors, use the built-in RGB() function:

        RGB(255,255,255) = 16777215 (white)
        RGB(0,0,255) = 16711680 (blue)
        RGB(255,0,0) = 255 (red)

    If you are familiar with Hex notation, you can go:

        .BackColor = &HFFFFFF& (white)
        .BackColor = &H00FF00& (green)
        .BackColor = &H0000FF& (red)

    Note however that the VB colors are coded "BGR" (as explained by dqmg) with red = &HFF, unlike the "internet colors" coded "RGB" with red = 0xff0000

    And you can also just click the builder button on any "color" property, pick your color in the dialog box and then remember the numeric  value.

    Good luck!
    LVL 39

    Assisted Solution

    And you will find a great free tool for tweaking colors (and other things) here:
    LVL 48

    Assisted Solution

    by:Gustav Brock
    Here's how to extract the discrete colours:

    Public Sub CompositeRGB( _
      ByVal lngRGB As Long, _
      ByRef intRed As Integer, _
      ByRef intGreen As Integer, _
      ByRef intBlue As Integer)
    ' Calculate discrete RGB colours from composite colour value.
    ' 1999-08-20. Cactus Data ApS, CPH
      If lngRGB < 0 Then
        ' Nothing to do.
        intRed = 0
        intGreen = 0
        intBlue = 0
        ' Dissolve composite RGB into discrete colours.
        intRed = lngRGB And vbRed
        intGreen = (lngRGB And vbGreen) / &H100
        intBlue = (lngRGB And vbBlue) / &H10000
      End If
      Debug.Print intRed, intGreen, intBlue

    End Sub
    LVL 4

    Author Comment

    thanks everyone.
    hmmm, 50 points won't go far.  increasing to split
    LVL 58

    Expert Comment

    It was kind of you to increase points and to aknowledge all contributions. Thanks!
    LVL 39

    Expert Comment

    You're welcome.  Glad to help and thank you very much for the points with "A" grade!  Thanks for the split.

    Happy Computing!


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    In the previous article, Using a Critera Form to Filter Records (, the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
    Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now