# Case statement help

**URL:** <https://forum.inductiveautomation.com/t/case-statement-help/73919>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [May 18, 2023, 6:43pm UTC](https://forum.inductiveautomation.com/t/case-statement-help/73919 "2023-05-18T18:43:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [May 18, 2023, 6:43pm UTC](https://forum.inductiveautomation.com/t/case-statement-help/73919/1 "2023-05-18T18:43:31Z")

</div>

I have this case statement:

```auto
case({view.params.Line} && {view.params.Pos},
11 && 1,
111,
11 && 2,
112,
11 && 3,
121,
11 && 4,
122,
11 && 5,
131,
11 && 6,
132,
11 && 7,
141,
11 && 8,
142,
999)

```

It always returns a 111. Is the case statement evaluating the first line and not the rest? I am trying to use a flex repeaters input params to change a labels text.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 18, 2023, 6:54pm UTC](https://forum.inductiveautomation.com/t/case-statement-help/73919/2 "2023-05-18T18:54:50Z")

</div>

Try this

```auto
case(concat({view.params.Line},{view.params.Pos}),
	"111", 111,
	"112", 112,
	"113", 121,
	"114", 122,
	"115", 131,
	"116", 132,
	"117", 141,
	"118", 142,
	999
)

```

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 18, 2023, 6:54pm UTC](https://forum.inductiveautomation.com/t/case-statement-help/73919/3 "2023-05-18T18:54:58Z")

</div>

> [@mjohnson0238](#):
>
> `11 && 1`

What are you expecting the result of this operation to be?

`&&` is the Logical AND operator, `11 && 1` would evaluate to `True`.

`&` is the Bitwise AND operator, ` 11 & 1` would evaluate to 1.

---

<div class="post-metadata">

**Author:** ![Siebold](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/siebold/32/47336_2.png) [@Siebold](https://forum.inductiveautomation.com/u/Siebold)\
**Post date:** [May 18, 2023, 6:58pm UTC](https://forum.inductiveautomation.com/t/case-statement-help/73919/4 "2023-05-18T18:58:02Z")

</div>

I would do the same but with a divider between the 2 numbers such as a | or , so that 1 and 11 don't evaluate the same as 11 and 1 for any future addition to the case statement. Instead you would get 1|11 and 11|1

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [May 18, 2023, 6:58pm UTC](https://forum.inductiveautomation.com/t/case-statement-help/73919/5 "2023-05-18T18:58:42Z")

</div>

I was looking for what @dkhayes117 has. Looks like I needed to concat the two params. It was my first time trying to use a case statement like that.

---

<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 18, 2023, 7:01pm UTC](https://forum.inductiveautomation.com/t/case-statement-help/73919/6 "2023-05-18T19:01:52Z")

</div>

Tidying up a bit makes it easier to see what's a case and what's the result ...

```auto
case({view.params.Line} && {view.params.Pos},
  11 && 1, 111,
  11 && 2, 112,
  11 && 3, 121,
  11 && 4, 122,
  11 && 5, 131,
  11 && 6, 132,
  11 && 7, 141,
  11 && 8, 142,
  999
)

```

However, if you test your logic as shown below you might find that it doesn't work as you think.

![Bitwise AND](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/2/8258b7eeabfbdf55cf98b6cafb8d7ad8dd45e3be.png)

Every one of those case conditions evaluates to `true`.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [May 18, 2023, 7:05pm UTC](https://forum.inductiveautomation.com/t/case-statement-help/73919/7 "2023-05-18T19:05:40Z")

</div>

understood, thanks

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [May 18, 2023, 7:08pm UTC](https://forum.inductiveautomation.com/t/case-statement-help/73919/8 "2023-05-18T19:08:32Z")

</div>

> [@mjohnson0238](#):
>
> Looks like I needed to concat the two params. It was my first time trying to use a case statement like that.

Another way would be to maintain a top level dictionary in a project script which would take the numbers and find the matching dictionary key then return the value. The expression would use `runScript()`, that way you could change your lookup dictionary without modifying your expression bindings.

that would look like this

```auto
someProject //script package name

myDict = {"11|1":111}

def lookupOnLinePos(line,pos):
    key = '%s|%s' % (line,pos)
    return myDict.get(key,999)

//in the expression
runScript("myProject.lookupLinePos",
    0, //only run when parameters change (poll off)
    {view.params.Line},
    {view.params.Pos}
)

```

I guess you could manage it with a DB table too.
