Article ID: 112061
Article Last Modified on 1/18/2007
Option Explicit
'-----------------------------------------------------------------
'PURPOSE: Returns red/green/blue color from RGB color value.
'ACCEPTS: RGB color value as Long, and component number as integer
' that represents the component color to return (1=red,
' 2=green, 3=blue).
'RETURNS: The intensity of the color component (0 - 255) as an
' integer or -1 indicating that an argument was invalid.
'-----------------------------------------------------------------
Function GetRGB (RGBval As Long, Num As Integer) As Integer
' Check if Num, RGBval are valid.
If Num > 0 And Num < 4 And RGBval > -1 And RGBval < 16777216 Then
GetRGB = RGBval \ 256 ^ (Num - 1) And 255
Else
' Return True (-1) if Num or RGBval are invalid.
GetRGB = True
End If
End Function
Macro Name Action Comment
---------------------------------------------
GetRGB MsgBox Display red component
MsgBox Display green component
MsgBox Display blue component
GetRGB Actions
-------------------------------------------------------------------
MsgBox:
Message: =GetRGB(Forms![Orders].Section(0).Backcolor,1) & ": Red"
MsgBox:
Message: =GetRGB(Forms![Orders].Section(0).Backcolor,2) & ": Green"
MsgBox:
Message: =GetRGB(Forms![Orders].Section(0).Backcolor,3) & ": Blue"
Additional query words: video screen
Keywords: kbhowto kbprogramming KB112061