Convert CommonDialog.color to RGB format?

Posted on 2004-11-29
Last Modified: 2008-01-09

Was just playing with the Common dialog box color picker. I noticed that it returns the color code in some other form rather than RGB.

Ex. Selecting 'Brown" color returned "4210816". Can I convert this value to RGB form?
Question by:sramesh2k
    LVL 34

    Author Comment

    Now reading this doc:
    LVL 53

    Accepted Solution

    Public Function ColorCodeToRGB(lColorCode As Long, iRed As Integer, iGreen As Integer, iBlue As Integer) As Boolean
    ' 1996/01/16 Return the individual colors for lColorCode.
    ' 1996/07/15 Use Tip 171: Determining RGB Color Values, MSDN July 1996.
    ' Enter with:
    '     lColorCode contains the color to be converted
    ' Return:
    '     iRed    contains the red component
    '     iGreen  the green component
    '     iBlue   the blue component
        Dim lColor As Long
        lColor = lColorCode      'work long
        iRed = lColor Mod &H100  'get red component
        lColor = lColor \ &H100  'divide
        iGreen = lColor Mod &H100 'get green component
        lColor = lColor \ &H100  'divide
        iBlue = lColor Mod &H100 'get blue component

        ColorCodeToRGB = True
    End Function

    LVL 34

    Author Comment

    Thanks. But VB does not seem to display the value in Long format. I selected the 1st color (reddish) and get this output : 8421631


    Text1.Text = cdlgColor.Color
    LVL 34

    Author Comment

    Got this resolved: This function helped

    Sub ConverttoRGB()
      R = C And 255              ' Get lowest 8 bits  - Red
      G = Int(C / 256) And 255   ' Get middle 8 bits  - Green
      B = Int(C / 65536) And 255 ' Get highest 8 bits - Blue
      out = R & "  " & G & "   " & B
    End Sub


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    737 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

    18 Experts available now in Live!

    Get 1:1 Help Now