Setting XLS colors in RPG2SQL - Support

Setting XLS colors in RPG2SQL

From Support

Jump to: navigation, search

Contents

Description

There are several commands in the RPG2SQL Integrator 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 will give you a very easy way to create your own customized color and an equally easy way to build them into your program!


What the User Guide Says

The RPG2SQL Integrator User Guide gives several commands that can be used to edit the color schemes of your XLS document.

The primary commands are:

  • SETSELECTIONBACKCOLOR: This XLS_Command function is used to set the background color for the selected cell range.
  • SETSELECTIONBFORECOLOR: This XLS_Command function is used to set the foreground color for the selected cell range.

The parameter for these functions is a single parameter (P1) which allows you to pass a value ranging from 0 to 16711935 indicating what color you would want the cell(s) attribute to be.


Example: To set the font color to red, you would have code similar to the following:

C                   Eval      Rtn=
XLS_Command(SQL_Socket:'SETSELECTIONBACKCOLOR':
                              '255')

The User Guide also lists several standard colors for you to use (listed below), but this does not describe how to create new colors. How do you select your own colors and use them within your XLS files?


How It All Works

Any artist would tell you that colors are created by combining different amounts of the primary colors. These colors are Red, Blue and Yellow.

While this is true in the physical world, this does not hold true in the digital world. Computers use combinations of the Red, Blue and Green lights to create all the various colors that you see. As result, all colors must be defined in terms of Red, Blue and Green in any computer software that you write or purchase. To display a color, each of the three primary digital colors are given a value ranging from 0 to 255 (8 bits). Note: this give you a total of 16,777,216 possible colors.

This holds true in the RPG2SQL Integrator as well, although it is not quite so obvious.

Although RPG2SQL Integrator requests only one value that will allow it define the color that you desire, all three primary digital colors are built into the value. It takes a little math to see how this is done.

Say we wish to create a greenish color that is created with the following combination: Blue: 98 Green: 173 Red: 75

NOTE: Any graphics editor can be used to create a color and provide you with the appropriate Red, Blue, Green values. You can use applications like MS Paint or Photoshop. You could also find free websites that can help.

Now we need to do a little math. The equation works like this:

   (((Blue ) * 256) * 256)  
  + ((Green) * 256)
  +  (Red  )

Substituting the values given above, you would get:

 (98 * 256 * 256)
 +    (173 * 256)
 +           (75)

which equals:

 (6422528) + (44288) + 75  =  6466891

If you give the value 6466891 to the RPG2SQL Integrator function call, it will set your color properly.

How to Create and Use a Color in RPG2SQL Integrator

RJS Software does not expect you to manually do any mathematics for your program. The above example was to simply show you what is involved in creating and using a custom color.

To create and use a color in RPG2SQL, you can follow these basic steps 1. Create your color.

NOTE: Any graphics editor can be used to create a color and provide you with the appropriate Red, Blue, Green values. You can use applications like MS Paint or Photoshop. You could also find free websites that can help.

2. Record the Red, Blue and Green values to use in your program.

3. In your program, create three numeric variables to represent the Red, Blue and Green colors.

For this example, the variables &RED, &BLUE and &GREEN will be used.

NOTE: These values could be passed into your program as parameters if you wanted to be creative and allow the color to be changed dynamically.

4. Create an additional numeric variable to hold the final color value.

For this example, the variable &COLOR will be used.

5. Add the following equation into your code:

&COLOR = (&BLUE * 65536) + (&GREEN * 256) + &RED

Note: This is not in an RPG format!

6. Any time you wish to use your color, you simply need to pass the &COLOR variable to the RPG2SQL Integrator function as a character string (needs a conversion).

Now you can use the Red, Green, Blue values that you can create through any graphics or painting program in your RPG2SQL Integrator coding!

Standard Color Values

Here are the standard colors that are listed in the RPG2SQL Integrator User Guide. I will give you the final value and then the RBG value to create it.

NOTE: I will use R for Red, G for Green and B for Blue in the following color examples:


ColorspaceRGB ValuespaceComponent 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


This article has been proofread by Nick as of 10:28, 01 February 2008 (Central Standard Time)


Excel XLS rpg2sql RPG2SQL color COLOR CELL cell RGB custom CUSTOM

Personal tools