O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

RGB Function

Syntax

RGB(red, green, blue)

red

Use: Required

Data Type: Integer

A number between 0 and 255, inclusive.

green

Use: Required

Data Type: Integer

A number between 0 and 255, inclusive.

blue

Use: Required

Data Type: Integer

A number between 0 and 255, inclusive.

Return Value

A Long integer representing the RGB color value.

Description

Returns a system color code that can be assigned to object color properties.

Rules at a Glance

  • The RGB color value represents the relative intensity of the red, green, and blue components of a pixel that produces a specific color on the display.

  • The RGB function assumes any argument greater than 255 is 255.

  • The following table demonstrates how the individual color values combine to create certain colors:

Color

Red

Green

Blue

Black

0

0

0

Blue

0

0

255

Green

0

255

0

Red

255

0

0

White

255

255

255

Programming Tips and Gotchas

  • The RGB value is derived with the following formula:

    RGB = red  + (green * 256) + (blue * 65536)

    In other words, the individual color components are stored in the opposite order one would expect. VBScript stores the red color component in the low-order byte of the long integer’s low-order word, the green color in the high-order byte of the low-order word, and the blue color in the low-order byte of the high-order word.

  • VBScript has a wide range of intrinsic color constants that can assign color values directly to color properties of objects. For a list of these, see Appendix B.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required