# Expression Comparisons

**URL:** <https://forum.inductiveautomation.com/t/expression-comparisons/11544>\
**Category:** Ignition\
**Created:** [April 20, 2016, 2:17pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544 "2016-04-20T14:17:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikehill100](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@mikehill100](https://forum.inductiveautomation.com/u/mikehill100)\
**Post date:** [April 20, 2016, 2:17pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544/1 "2016-04-20T14:17:29Z")

</div>

In Python you can say:

if 2 \< 3 \< 4:  
print ‘Hello’

and it will be very clear and it will work.

In expression language if you say:  
if( 2 \< 3 \< 4, ‘Hello’, ‘Goodbye’)

it will give you an error because it can’t compare three values like that.

The best way around this I have found is:  
if( 2 \< 3 && 3 \< 4, ‘Hello’, ‘Goodbye’)

but in practice and for longer comparisons it quickly becomes less clear than the Python version.

if( myVal1 \< myVal2 && myVal2 \< myVal3 && myVal3 \< myVal4, ‘Hello’, ‘Goodbye’)

Is there another way to do this or has Python spoiled me?

Any ideas are appreciated.

Thanks,

- Mike

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 20, 2016, 2:42pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544/2 "2016-04-20T14:42:55Z")

</div>

Python has spoiled you. 😆

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [April 20, 2016, 6:53pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544/3 "2016-04-20T18:53:42Z")

</div>

I’ve never used it before but I believe the [switch](https://support.inductiveautomation.com/usermanuals/ignition/gen_logic_switch.htm) function will handle multiple evaluations and returns.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 20, 2016, 11:13pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544/4 "2016-04-20T23:13:48Z")

</div>

If you really must, you can do this with python via [objectScript()](http://marketplace.inductiveautomation.com/moduledetail?moduleId=93) or the latest runScript():`objectScript('args[0] < args[1] < args[2]',
  {Root Container.property1},
  {Root Container.property2},
  {Root Container.property3})`Though I doubt I’d actually do this unless one or more of the arguments had execution side effects or big delays.  
{ /end shameless plug for one of my modules 😆 }

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 3, 2023, 9:19pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544/5 "2023-05-03T21:19:40Z")

</div>

I have 3 LED Displays that have a script changing them to a 1 or 0 in the value that in turn changes the text. I now need to check each LED data value field to see if they are all 1's, if they are it will will return true (1) and enable a button, if any 1 of the 3 fields are 0, it should return a false (0) and not enable the button. I have tried multiple ways but cannot seem to get the statement right.

Current statement:

If({Root Container.Displacement Display.value} = {Root Container.Generic Indicator.value} = {Root Container.Serial Number LED Display.value},1,0)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 3, 2023, 9:27pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544/6 "2023-05-03T21:27:09Z")

</div>

Change the expression to a simple logical AND.

```auto
{Root Container.Displacement Display.value} 
  && {Root Container.Generic Indicator.value} 
  && {Root Container.Serial Number LED Display.value}

```

That will return a boolean true or false.

Expression functions work a little like Excel formulas (but without the `=` operator at the start).

* * *

Tip: use the \</\> button when posting code. It preserves tabs, does syntax highlighting and makes it obvious where the code starts and ends.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 3, 2023, 10:13pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544/7 "2023-05-03T22:13:04Z")

</div>

I implemented these a while ago, but seeing this topic pushed me to release an update to [Ignition Extensions](https://forum.inductiveautomation.com/t/ignition-extensions-convenience-utilities-for-advanced-users/64615/72) that adds an `anyOf` expression function that could be useful for collapsing repeated boolean checks.

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 4, 2023, 8:07pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544/8 "2023-05-04T20:07:42Z")

</div>

Thank you transistor. This is working like I hoped. Is there a way to bind this boolean to a button enable/disable. I have been trying to use this to enable a button but have been unsuccessful. If the boolean is a 1 the button is on and if 0 the button is disabled.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 4, 2023, 8:11pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544/9 "2023-05-04T20:11:15Z")

</div>

Will the expression not work in the enable property?

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 4, 2023, 8:21pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544/10 "2023-05-04T20:21:06Z")

</div>

It does not seem to in the format Transistor gave me. I also tried an if statement with Transistors syntax with the same results. When you say enable property do you mean the set property?

---

<div class="post-metadata">

**Author:** ![Chad\_Campbell](https://avatars.discourse-cdn.com/v4/letter/c/c2a13f/32.png) [@Chad\_Campbell](https://forum.inductiveautomation.com/u/Chad_Campbell)\
**Post date:** [May 4, 2023, 8:25pm UTC](https://forum.inductiveautomation.com/t/expression-comparisons/11544/11 "2023-05-04T20:25:08Z")

</div>

HaHa! I'm a newb. I found it in the filter for the vision property filter for all instead of Basic.

Thank you Jordan.
