SteveMyres Posted August 11, 2010 Share Posted August 11, 2010 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'" endif 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 More sharing options...
AzeoTech Posted August 12, 2010 Share Posted August 12, 2010 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 More sharing options...
SteveMyres Posted August 12, 2010 Author Share Posted August 12, 2010 Cool function! I wasn't even aware of it. I'll bet I find lots of places it works well. Link to comment Share on other sites More sharing options...
AzeoTech Posted August 12, 2010 Share Posted August 12, 2010 Yeah, its a pretty standard function across most languages. I think VB uses iif(). C and JavaScript use ? : syntax. Anyhow, you can nest them too. Its just a function that takes three expressions. Link to comment Share on other sites More sharing options...
SteveMyres Posted August 12, 2010 Author Share Posted August 12, 2010 OK, now that you mention it, "? :" does sound vaguely familiar. I think Excel also implements it as "if()". Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.