Displaying text based on a tag value

I’m looking to display text of my step description based on a tag value for the current step my machine is in using a text field.

For example, if the tag RXStep (which is bound to a PLC tag reading in an integer for the step a specific machine is in) reads 0 then print “Step: 0 Idle”.

I tried using If statements in Expression tab of the text field property binding window but keep getting errors no matter how I formatted them.

if ({Reactor_Status.RXStep} = 0, “Step: 0 Idle”)
if ({Reactor_Status.RXStep} = 1, “Step: 1 Pressurize”)
if ({Reactor_Status.RXStep} = 2, “Step: 2 Leak Test”)
if ({Reactor_Status.RXStep} = 3, “Step: 3 Calculate Product Qty”)

I have about 40 different steps. Is there a away to do this with a text field or better way to do this? I’ve looked at several forums but found nothing similar. Thanks!

Is this Vision, or Perspective? Do you expect to need to add additional step labels frequently/ever?

Vision. No, these steps will likely never change.

You could use nested if statements but you’d need commas at the end of each line and closing brackets. Something like,

if ({Reactor_Status.RXStep} = 0, "Step: 0 Idle"),
if ({Reactor_Status.RXStep} = 1, "Step: 1 Pressurize"),
if ({Reactor_Status.RXStep} = 2, "Step: 2 Leak Test"),
if ({Reactor_Status.RXStep} = 3, "Step: 3 Calculate Product Qty"),
etc., etc.,
"Step: 40 Last step"

The case function would be much easier:

  0, "Step: 0 Idle",
  1, "Step: 1 Pressurize",
  2, "Step: 2 Leak Test",
  3, "Step: 3 Calculate Product Qty",
  etc., etc.,
  "Step: 40 Last step"    // default


Tip: When posting code, select the block of code and press the </> button to format it. It will preserve indentation and do some syntax highlighting for you. It also prevents the forum engine putting in fancy “ ” inverted commas which have to be edited out when copying your post.

So, if you’re only doing this once, I like the case statement, or if you might want additional customization with each step, you can use the Style Customizer to bind arbitrary component properties (including text) to a driving property.

You could also store a dataset on a tag/client tag somewhere and use the lookup expression; that would allow you to update the text in one place (if you’re using this label in multiple windows).

Thanks so much! I will try these.

I tried the case statement just to test. I copied it exactly as shown below in the Expression tab of the property binding: text field window. I keep getting “Syntax Error on Token: ‘LONG CONST’ (Line 2 , Char 3)” error. Any ideas what could cause this? Are you able to use a tag as the value to inspect? I couldn’t find any examples using a tag instead of a constant.

0, “Step: 0 Idle”,
1, “Step: 1 Pressurize”,
2, “Step: 2 Leak Test”,
3, “Step: 3 Calculate Product Qty”,

I also tried the style customizer, the only thing with the is that I would like one line of text to show if possible. The style customizer shows all the steps at once and takes up too much room.

Thanks again!

You haven’t formatted your code properly again. (Re-read the tip in my previous post.) As a result we don’t know if you have got “Step: 0 Idle” with “66 - 99” quotation marks or (what you should have) "Step: 0 Idle" with plain ASCII double-quotes.

Please edit both posts with the 🖉 edit link and then select any code blocks and press the </> button to format it. Check that the quote characters are the actual ones in your expression. Someone should be able to find the problem then.

1 Like

You’re missing the first comma


I had made a template for such things. Feel free to use if you find it helpful.

Step Indicator Example.zip (4.8 KB)