Expression tag PLC reference


I inherited a system that as lot of scripting etc. One of tag was using switch. I was wondering is it possible to reference a PLC tag directly?
Second is it a good approach ?

This is an expression, not scripting.

{[.]Line} is a tag reference.

You could replace 1 with similar syntax referencing some OPC tag.

You should probably do some reading or watch some IU videos re: expressions and scripting.

You could also convert them to case | Ignition User Manual statements which are a bit easier to read.

case(
    {[.]Line},
    "LineA", 1,
    "LineB", 2,
    "LineC", 3,
    "LineD", 4,
    "-"
)

Note that the original expression is inconsistent. In one case it returns a string, "-" and in all the others it returns an integer. This is likely to cause problems elsewhere. (My expression does the same as it's merely a conversion from switch to case.)

Tip: for future code questions, please see Wiki - how to post code on this forum.

1 Like