You can help by commenting or suggesting your edit directly into the transcript. We'll review any changes before posting them. All comments are completely anonymous. For any comments that need a reply, consider emailing email@example.com.
1:37Property Binding – Bidirectional
Take topic challenge
Expression Binding – Switch
Learn how to use the switch function in expression bindings to evaluate conditional statements.
Video recorded using: Ignition 8.1
Transcript(open in window)
[00:00] In this lesson, I'll demonstrate how to translate an integer value into a string using an expression binding with a switch function. I have an integer tag that I'd like to display on my screen, but I want the integer values to be changed to strings that show the state represented by each value. In order to do this, I've set up a label component and I could add a binding to the label's text property. I can use the expression language and find what I'm looking for in the logic section. Now, I could set this up with some nested if statements where each false return contains another if statement. However, the switch expression is much easier to write. This function can have a variable number of arguments. The first argument takes the value we want to check. Then the next set of arguments will be the cases or the different values it could possibly be. Then the final set of arguments will be the return values. I'll copy over a commented version of the syntax that makes it easier for me to fill out.
[01:05] I'll also add some new lines to make this more readable and divide those arguments into groups. So for this situation, I want to use my integer tag as the value. Then I know that the numbers 0, 1, 2, and 3 represent some state. So those will be my cases. And then I can add the return values. These are gonna be the strings, and I'll fill them out in the same order that the cases were listed. So if the tag is zero, that means that it's "Off". One means "Running", two means "Manual" and three means "Faulted". Then the function needs one last argument for the default return, and this will be the fallback if none of the other conditions are met. So I'll make this "Unknown".
[02:07] Now that my binding is set up, I can change the tag value. This is a quick and easy way to translate integer values into strings using the expression language.