Binding Properties to the Outcome of an Expression
An expression binding is one of the most powerful kinds of property bindings. It uses a simple expression language to calculate a value. This expression can involve lots of dynamic data, such as other properties, Tag values, results of Python scripts, queries, and so on. You can use expressions for many different purposes. Anytime information needs to be massaged, manipulated, extracted, combined, split, and so on - think expressions!
For a complete list of the Expression Functions, see the Expression Functions page in the Appendix.
You have a button that starts a batch, but you only want to let it be pressed after the operator has entered a scale weight. Bind the button's enabled property to:
You want to display a process's current state, translating a code from the PLC to a human-readable string, use one of these two expressions (they're equivalent)
See also: Expression Overview and Syntax
Expression Function Examples
You can use an expression binding to concatenate strings resulting in a new string that reflects the concatenation of different strings.
The function starts with
CONCAT() and inside the function is a list of strings. They can be manually typed like
"42" or they can come from Tags or properties.
You have a Date, and need to extract the year, and concatenate the word "Vintage" to the end for a label display. Bind a label's text property to:
Celsius to Fahrenheit
Use an expression binding to convert a temperature from Celsius to Fahrenheit. This is an example of how expression binding can handle calculations.
The reference to the Celsius temperature can come from a property or a tag. As the property or the tag changes, so does the expression binding.
You can format a date in an expression binding by using the
To make a label that updates to show the current time:
- Drag a Label component onto the window.
- Select the label's Text property binding icon and select Expression binding.
Enter the following code into the expression, and click OK.
dateFormatfunction takes two arguments. The first argument is any date type variable. This can include another function (like now) that returns a date type. The second argument refers to the date format that you want returned. The
nowfunction returns the current time and in this case it will update every second.
For more information on the date formatting expression, see the Appendix.
You can manipulate dates in expression bindings such as a date addition/subtraction with the
dateArithmetic function. This is important when you want to use the expression bindings to select a date that is offset by a certain amount.
The following example will return the time 15 minutes ago by using the dateArithmetic expression function:
You can use various bit functions in expression bindings like
getBit to return individual bits of a word.
Assuming a tag path 'Folder/BitTag', the following would return the binary representation of the tag's value at the 0 position
For more details on the getBit function please see the getBit page in the Appendix.
You have 3 bits in a PLC, only one of which will be on at a time. You want to turn these three bits into a single integer (0,1,2) to drive a component's Styles. Bind a custom integer property to:
You can use the switch function in expression bindings to evaluate conditional statements. This function acts like the switch statement in C-like programming languages. It takes the value argument and compares it to each of the case1 through caseN expressions.
The following example returns the string
"Running" when it is given the value of
1. Its options are
2. And when comparing the value to the options the switch statement returns one of the corresponding results. If a result cannot be found, a fail-over option is returned.
You can use expression bindings to return true or false based on different conditions.
Consider the following expression that references the Tag with a path of 'Folder/Machine State':
The above expression simply tests the value of the Machine State tag. If the value of the Machine State Tag is ever equal to 0 then the above expression would return true. In every case where Machine State is not equal to 0, then the expression would return false.
It is possible to check for multiple conditions in the same expression. If you have two boolean tags and you only want the expression to return true if both tags are true then the binding would look like:
- No labels