VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This will get the RGB values of a long color. This only works if you don't use system colors.

by Cache (3 Submissions)
Category: Graphics
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 19th March 2003
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This will get the RGB values of a long color. This only works if you don't use system colors.

Rate This will get the RGB values of a long color. This only works if you don't use system colors.




Private Sub Command1_Click()
Dim R As Integer, G As Integer, B As Integer, Color As ColorConstants
    Color = Me.BackColor
    'This will not return anything if you are using system colors.
    Call GetRGB(R%, G%, B%, Color)
    Debug.Print "Red is " & R%
    Debug.Print "Green is " & G%
    Debug.Print "Blue is " & B%
End Sub

Public Function GetRGB(ByRef R As Integer, ByRef G As Integer, _
    ByRef B As Integer, ByVal Color As ColorConstants)
Dim X As Long, Total As Double, TempTotal As Double, _
    NewColor As Long
    NewColor = Color
    'Get's the Blue color
    For X = 255 To 0 Step -1
        If 65536 * X <= NewColor Then
            B% = X
            NewColor = NewColor - (65536 * X)
            Exit For
        End If
        DoEvents
    Next X
    'Get's the Green color
    For X = 255 To 0 Step -1
        If 256 * X <= NewColor Then
            G% = X
            NewColor = NewColor - (256 * X)
            Exit For
        End If
        DoEvents
    Next X
    'Get's the Red color
    For X = 255 To 0 Step -1
        If X <= NewColor Then
            R% = X
            NewColor = NewColor - X
            Exit For
        End If
        DoEvents
    Next X
End Function

Download this snippet    Add to My Saved Code

This will get the RGB values of a long color. This only works if you don't use system colors. Comments

No comments have been posted about This will get the RGB values of a long color. This only works if you don't use system colors.. Why not be the first to post a comment about This will get the RGB values of a long color. This only works if you don't use system colors..

Post your comment

Subject:
Message:
0/1000 characters