See Also Example
Returns a long integer representing an RGB color value.
Syntax
RGB (red, green, blue)
Remarks
The RGB function has these parts:
Part Description
red Integer in the range of 0 to 255, inclusive, that represents the red component of the color.
green Integer in the range of 0 to 255, inclusive, that represents the green component of the color.
blue Integer in the range of 0 to 255, inclusive, that represents the blue component of the color.
Visual Basic methods and properties that accept a color specification expect that specification to be a long integer representing an RGB color value. An RGB color value specifies the relative intensity of red, green, and blue, which taken together cause a specific color to be displayed.
If the value for any argument to RGB exceeds 255, it is assumed to be 255.
The following table shows the hexadecimal representation for some standard colors, their corresponding RGB values, and the red, green and blue components for each:
Color | RGB value | Red value | Green value | Blue value |
Black | &H00 | | | |
Blue | &HFF0000 | | | |
Green | &HFF00 | | | |
Cyan | &HFFFF00 | | | |
Red | &HFF | | | |
Magenta | &HFF00FF | | | |
Yellow | &HFFFF | | | |
White | &HFFFFFF | | | |
QBColor Function
The RGB function example displays a variety of color shades on a form. To try this example, paste the code into the Declarations section of a form. Then press F5 and click the form.
Sub Form_Click ()
Dim I ' Declare variable.
Cls ' Clear form
ScaleHeight = 128 ' Divide form into 128 parts.
For I = 0 To 126 Step 2 ' Draw a colored box.
Line (0, I)-(ScaleWidth, I + 2), RGB(I, 64 + I, 128 + I),BF
Next I
End Sub