Trust ID PBCEX logo 300x102

Control text color with script

7 years 3 months ago 7 years 3 months ago by Rutger Koperdraad.
Rutger Koperdraad
Platinum Boarder
Platinum Boarder
Posts: 1566
Topic Author
Control text color with script #2694
A customer asked:

Can I make a funtion to change a color in a text, variable or rectangle, depending on a database colomn... So when the DEPARTMENT column has "DEP1", then red and when "DEP2" then green?

Yes, that is possible, provided that you have the Ultimate edition. The steps to get this configured in the designer are:

1. Open the designer and add the following function to the Functions tab of the Properties window:
def depcolor(dep):
  s = str(dep)
  if s == 'DEP1':
    return 'Red'
  elif s == 'DEP2':
    return 'Green'
    return 'Black'
2. Add a variable called dep to the Variables tab of the Properties window and set its value to DEP1.

3. Select the DEPARTMENT column in the Data tab on the left-hand side of the main window, drag it to the Variables tab in the Properties window and drop it in the value text box of dep (in version 7.0 drag-and-drop is not available and you have to map the variable in the mappings window after finishing the steps below).

4. Select the text object whose color you want to control and go to the Expressions tab of the Properties window.

5. Type in the expression box for the Foreground property the following expression:

Rutger Koperdraad
Senior Software Engineer

"A reasonable man adapts himself to the world. The unreasonable man persists in trying to adapt the world to himself. All progress, therefore, depends on the unreasonable man." (Bernard Shaw)


The forum is in read only mode.