Dynamically changing text labels

I’d like to have a label that describes the status of each of my conveyors. For example, when DB value “N_convey1” = 0, the status label should read “Stopped”, 1 should read “running”, 2 “Auto”, 3, “E-Stop”. How would I accomplish this?

This would be a good application for the switch() function in the expression language.

First, create an integer dynamic property on the Label component.

Bind this Integer to the database value that holds your conveyor status (using DB-Browse or SQL Query binding)

Finally, bind the text property of your label to an expression such as:

switch({Root Container.MyLabel.statusProperty}, 0,1,2,3, "Stopped", "Running", "Auto", "E-Stop", "UNKNOWN CONVEYOR STATUS")

That last value is a catch-all value in case the status property is a number besides 0-3.

If you have lots of labels that need to display the same thing, you can let SQL do the work for you. Set up a “lookup table” in your database. It would be a simple table, such as:

ConveyorStatusCodes
Code | Description

0 | “Stopped”
1 | “Running”
2 | “Auto”
3 | “E-Stop”

Then, simply bind the text of your labels to a SQL query such as:

SELECT CODES.Description FROM ConveyorStatusCodes AS CODES, ConveyorStatusTable AS STATUS WHERE STATUS.N_convey1 = CODES.Code

Hope this helps,

1 Like