Conditional expressions

Recommended Posts

I want to create a display element but the expression for it would need to contain conditionals, but you can't put if's and other conditionals in an expression. Putting this in the OnPaint() of the element works:

strExpression = "'Mix Tank 1 '" + " + MixTankStatus[MixTank_1_Status]"
if (MixTank_1_Status == 2)
   strExpression = strExpression + "+ 'Component nnn'"

which creates an evaluable expression in the form of a string and sticks it in the strExpression of the component.

Is there a cleaner more elegant way to do this? Not crazy about having to put the same code in a recurring sequence but that would certainly work. I guess putting the code in a callable sequence and using the function return in the expression would feel a little cleaner, because it's still the screen refresh driving the calculation.

Link to comment
Share on other sites

Yes, use the iif() function. iif stands for inline if. It'd be something like this in your expression:

iif(mixtank_1_status == 2, 'Mix Tank 1 ' + mixtankstatus[mixtank_1_status] + 'Component nnn', 'Mix Tank 1 ' + mixtankstatus[mixtank_1_status])

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.