Type casting tags to compare in expression binding

Hello,

I have a tag (let's say called A) which contains a Short number.

I would like to use this tag to run the following code:

if (TagA = 16)
Return TagB
else
Return TagC

I am doing this in the Path property using expression binding as:

if (ToInteger({Root Container.TagPath}+"/Metering/TAP_POSITION")=16,
"[default]Bluestone/86B1/OP_ST 1",
"[default]Bluestone/86B1/OP_ST 2")

However, return statment is always TAG B. It does not return TAG C when TAG A is not 16.

Is anyone able to advise what I am doing wrong?

Thank you,
Ethan

See this for properly formatting code:

this is not doing what you think it is doing. You are trying to convert a string to an integer.

{Root Container.TagPath} will resolve to some string path, which will then concatenate to the other string.

Essentially your expression looks like this:

if(toInteger("path/to/tagA" + "/Metering/TAP_POSITION") = 16,"[default]Bluestone/86B1/OP_ST 1","[defalut]Blueston/86B1/OP_ST 2") 

Instead, create a custom property on the window, perhaps the Root Container, and use an indirect tag binding to get the actual value of TagA. Same thing for TagB, and Tag C if what you want is the value of the tags and not the paths.

Then use the expression like this:

if(toInteger({Tag.A.Property}) = 16, {Tag.B.Property},{Tag.C.Property})

Honestly, there might be a better way, but I don't know exactly what you end goal is here. Also, since TagA is a short and it can hold the value 16, there is no need for it to be converted to an integer. So really the toInteger() expression is unneeded.

2 Likes

Hey lrose,

Thank you very much for the help. I implemented you suggestion and this worked.
For my understanding, why is it that when I concatenate a string (which is a path of a tag containing a Short) and try to type cast it to an INT, why does it try to convert the string instead of the value contained at the string path?

Thanks again.

It doesn't automatically resolve a string to a tag path. To it, a string is just a string. You have to tell it to resolve the string to a tag. There are other ways to do it but this way is the best practice.

4 Likes