If Statement

I have the following in a Transaction Group Triggered Expression Item.

I would like the Value of the expression Items to change to the names based on the left most charater of the serial number.

What is wrong with the following If statement??

if (left{[~]SerialNumber}) = ‘A’:
elif (left{[~]SerialNumber}) = ‘B’:
elif(left{[~]SerialNumber}) = ‘C’:

Thanks In Advance!


Expression Items aren’t Python based. For multiple If…Then conditions, consider using the Switch function:

SWITCH ( left({[~]SerialNumber},1), "A", "B", "C", "Lambda","LambdaCover","0351", "Unknown" )

Information on the Switch function can be found here.


I Get the diff between Exp and Scripting now I think…

Sorry for being such a newb!!..

Hi, Ive got a similar issue, I can get a simple IF to work, to bind the colour of a text to a condition,

IF(({Brac Tags/Analog_In/PET_150}>50||{Brac Tags/Analog_In/PET_150}<25),color(217,0,0),color(0,0,0))

But I want a few more conditions than this,and trying to make the simple one a SWITCH from above or a few tries similar doesn’t work, gives me Switch does not work with multiple arguments or similar…Also, what is the ,1 for end of line 1…I tried the link to the manual it doesn’t work, and speaking of, where is the manual mentioned often in training…

SWITCH ({Brac Tags/Analog_In/PET_150},1,

It doesn’t like the greater than line 2, and If I put full tag string in there it says switch doesnt work with 7 arguments.

You can’t evaluate a greater than or less than in a switch function. A workaround as per this thread is to use binEnum like this:

  binEnum({Brac Tags/Analog_In/PET_150}=1,
          {Brac Tags/Analog_In/PET_150}>50,
          {Brac Tags/Analog_In/PET_150}<25),
'color(217,0,0)',        //result 1 
'color(217,217,0)',        //result 2 
'color(0,0,0)',      //result 3 
'none')       //default

The manual page for Switch is here.

1 Like

Well Thank you Sir That is much appreciated, I’ll give it a go and check that thread also,
Cheers, Neil

This is a broken link, please provide some information on a switch case .

You’ll find a link to switch under the logic section of Expression Functions documentation in the online Ignition user manual.

1 Like

So we need an if statement for 3 tags, should we look at the switch statement or binEnum? Neither appear to work.

Show us what you’re trying, what you’re getting, and what you’d like to get.


Always returns “1”

Trying to setup a multistate indicator with more than 1 - input. I need a case switch statement I can plug into a memory location(via expression)

I see an “or” operator in there. Ignition’s expression order of operation isn’t normal. Try adding parentheses around your comparisons.

Do you want a result of 1 if either of your first conditions is true and 2 if neither is true? If so, what you have should work, assuming the relative tag paths are correct.

Or do you want a result of 1 if the first condition is true and a result of 2 if the second condition is true? There are multiple ways to do this, depending on what result you want if both conditions are true or both are false. Here's an example using if that ignores the second condition if the first condition is true:

// Return 1 if first condition is true (regardless of second condition).
if({[.]…/CTR_VAC_ROLL_A_MODE}>0, 1,
	// Return 2 if first condition is false and second condition is true.
	if({[.]…/CTR_VAC_ROLL_B_MODE_TENSION}>0, 2,
		// Return zero if neither is true.

A simpler way to get the same result would use binEnum:

// Returns index of first true condition:
// 0 indicates both conditions false.
// 1 indicates first condition true, regardless of second condition.
// 2 indicates second condition true and first condition is false.

Or use binEnc to capture all possible states:

// 0 (binary 00) indicates both conditions false.
// 1 (binary 01) indicates first condition true.
// 2 (binary 10) indicates second condition true.
// 3 (binary 11) indicates both conditions true.

Use switch or case to get different results for different values of a single tag/property. Use binEnum (to get index of first true condition) or binEnc (to get a single value representing state of all conditions) for multiple true/false conditions.


This worked well for me, thanks for the help.

1, //result 1
2, //result 2
3, //result 3
99) //default

1 Like