Overview
There are several commands in the RPG2SQL that will allow you to set the color of a cell or group of cells in an XLS document. But how do you create and set your own color schemes within these commands?
This article shows you an easy way to create your own customized colors and build them into your program.
Command, Functions, and Parameters for Editing Color Schemes
You use the XLS_Command to edit the color schemes of an XLS document. The XLS_Command has two functions for setting the color scheme:
- SETSELECTIONBACKCOLOR - sets the background color for the selected cell range.
- SETSELECTIONBFORECOLOR - sets the foreground color for the selected cell range.
These functions have one parameter, which is a value from 0 to 16711935 that indicates the color.
For example: To set the font color to red, use:
C Eval Rtn=
XLS_Command(SQL_Socket:'SETSELECTIONBACKCOLOR':
'255')
See below for instructions on how to determine parameter values for any color and a list of parameter values for standard colors.
How RPG2SQL Parameter Values for Colors Work
Note: RJS Software does not expect you to manually do any of the math in this section. This section merely shows you how custom colors work in RPG2SQL for illustrative purposes.
With paints, you create new colors by combining the primary colors: red, yellow, and blue. However, when you are using lights - such as on computer monitors - colors work differently. With lights, you create new colors by combining the digital primary colors: red, green, and blue (RGB).
To define a color in terms of red, green, and blue (RGB), you give each of the three primary digital colors a value from 0 to 255 (8 bits). This gives you a total of 16,777,216 possible colors.
However, RPG2SQL uses only one value to define the color. The way this works is that all three primary digital colors are built into that one value. It takes a little math to see how this works.
Say you wish to create a greenish color with the following combination:
- Red: 75
- Green: 173
- Blue: 98
Note: To create a color and view the corresponding RGB values, you can use any graphic-editing program, including Microsoft Paint or Photoshop. There are also free websites you can refer to.
The following equation converts the RGB color value into a color value for RPG2SQL:
(Blue * 256 * 256)
+ (Green * 256)
+ Red
Substituting the values listed above, you get:
(98 * 256 * 256)
+ (173 * 256)
+ (75)
...which equals:
(6422528) + (44288) + 75 = 6466891
So the parameter value 6466891 in RPG2SQL creates the original color.
Creating and Using a Color in RPG2SQL
To easily create and use a color in RPG2SQL:
- Using a graphic-editing program, such Microsoft Paint or Photoshop, create a color and make note of the color's RGB values. If you need more help with this step, there are also free websites you can refer to.
- In your program, create three numeric variables to represent the Red, Blue and Green colors.
For example: &RED, &BLUE, and &GREEN
Note: If you want to change the color dynamically, you can pass these values into your program as parameters.
- Create an additional numeric variable to hold the final color value.
For example: &COLOR
- Add the following equation to your code:
&COLOR = (&BLUE * 65536) + (&GREEN * 256) + &RED
Note: This is not in an RPG format.
- When you want to use the color, convert the &COLOR variable a character string and pass it to the RPG2SQL function.
Now you can use any RGB color that you can create through a graphic-editng program in your RPG2SQL coding.
Reference of Standard Color Values
The following are values for standard colors:
Color | Parameter Value | Component Values |
Black: | 0 | R=0 | B=0 | G=0 |
Blue: | 16711680 | R=0 | B=255 | G=0 |
Cyan: | 16776960 | R=0 | B=255 | G=255 |
Green: | 65280 | R=0 | B=0 | G=255 |
Magenta: | 16711935 | R=255 | B=255 | G=0 |
Red: | 255 | R=255 | B=0 | G=0 |
White: | 16777215 | R=255 | B=255 | G=255 |
Yellow: | 65535 | R=255 | B=0 | G=255 |