RGB - VBScript
Overview
The RGB command in VB Script is used to create a color value from the specified red, green, and blue components. This color value can then be used to set the color of text, shapes, or other objects in VB Script applications.
Syntax
RGB(Red, Green, Blue)
where:
Redis the red component of the color, a value between 0 and 255.Greenis the green component of the color, a value between 0 and 255.Blueis the blue component of the color, a value between 0 and 255.
Options/Flags
None.
Examples
To create a bright red color, use the following code:
Dim colorRed As Integer
colorRed = RGB(255, 0, 0)
To create a medium green color, use the following code:
Dim colorGreen As Integer
colorGreen = RGB(0, 128, 0)
To create a dark blue color, use the following code:
Dim colorBlue As Integer
colorBlue = RGB(0, 0, 128)
Common Issues
Ensure that the values specified for the red, green, and blue components are within the range of 0 to 255. If values outside this range are specified, the resulting color will be incorrect.
Integration
The RGB command can be combined with other VB Script commands to create more complex color effects. For example, the following code sets the background color of a form to a light gray color:
Form1.BackColor = RGB(224, 224, 224)
Related Commands
ForeColor: Sets the foreground color of text.BackColor: Sets the background color of an object.