Multiple condition Expression - Nested If Statement?

You have ORed your three checks so that if any one of them is within limits then True is returned. You need to AND them.

If your if returns true or false, you don't need an if.

limit_l1 < tag1 && tag1 < limit_h1
&&
limit_l2 < tag2 && tag2 < limit_h2
&&
limit_l3 < tag3 && tag3 < limit_h3 
8 Likes

Hello

if({tag0}=1,"ON",
    if({limit_l1} < tag1 && tag1 <{ limit_h1}
       &&
      { limit_l2} < tag2 && tag2 < {limit_h2}
       &&
       {limit_l3} < tag3 && tag3 <{ limit_h3}, True, False),
   "OFF")
   

I am trying to use this code in Expression binding if tag 0 is 1 it should check if tag1,2,3 are in limits if in limits it has to return True else False. If the tag 0 is 0 it has to return OFF But i am getting runtime exception.

if({tag0}=1,
    if({limit_l1} < tag1 && tag1 <{ limit_h1}
       &&
      { limit_l2} < tag2 && tag2 < {limit_h2}
       &&
       {limit_l3} < tag3 && tag3 <{ limit_h3}, True, False),
   "OFF")

Try removing "ON",

Tried its still showing error.

What is the exception message? You can examine it at the bottom of the binding editor.

Your expression can return boolean true or false but can also return a string OFF. That doesn't look right and suggests some confusion or poor design.

It is showing runtime exception

"Runtime Exception: Function if(condition, true return, false return) can not work with one arguments."

Post a nicely cropped screengrab showing the binding, the expression structure and the code.

You also need to explain why your function can return either a boolean or a string.


The function has to return either true, false or OFF so that i can map separate color for each state.

don't know how but the error is resolved thank you.

I'd say this will come back to bite you later.

Instead of passing true, false and OFF to the map transform pass values OK, Fault and OFF (or a numeric code) and use the Fallback option. This would be more readable.

I will surely change thank you.