# Struggle with a Switch

**URL:** <https://forum.inductiveautomation.com/t/struggle-with-a-switch/15173>\
**Category:** General Discussion\
**Created:** [August 27, 2017, 2:25am UTC](https://forum.inductiveautomation.com/t/struggle-with-a-switch/15173 "2017-08-27T02:25:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pam3636](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@Pam3636](https://forum.inductiveautomation.com/u/Pam3636)\
**Post date:** [August 27, 2017, 2:25am UTC](https://forum.inductiveautomation.com/t/struggle-with-a-switch/15173/1 "2017-08-27T02:25:05Z")

</div>

I’ve been struggling with this for days. About to pull my hair out.

THIS WORKS

switch({myProperty},  
1, 2,  
“x”, 22,  
99  
)

THIS DOES NOT WORK

switch({myProperty},  
1, 2,  
22, ‘x’,  
99  
)

and returns:

Type mismatch: Argument 4 for function ‘switch(etc…)’ is an invalid type

please send help!

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 27, 2017, 2:59am UTC](https://forum.inductiveautomation.com/t/struggle-with-a-switch/15173/2 "2017-08-27T02:59:07Z")

</div>

Seems like in the second example you’re trying to return mixed types as the result of the switch function.

---

<div class="post-metadata">

**Author:** ![Pam3636](https://avatars.discourse-cdn.com/v4/letter/p/bc79bd/32.png) [@Pam3636](https://forum.inductiveautomation.com/u/Pam3636)\
**Post date:** [August 27, 2017, 5:29pm UTC](https://forum.inductiveautomation.com/t/struggle-with-a-switch/15173/3 "2017-08-27T17:29:42Z")

</div>

OK, I got it to work by putting every return in quotes, even the numbers. It screwed me up because sometimes mixed types work!

This works:

switch({MyProperty},  
1, 2, 3, 4, 5,  
‘a’, ‘b’, ‘c’, 44, 55,  
‘none’  
)

This doesn’t work:

switch({MyProperty},  
1, 2, 3, 4, 5,  
11, 12, ‘c’, ‘d’, ‘e’,  
‘none’  
)

it seems as long as the last value is an integer, it’ll work…

But I have it working by putting all the returns in quotes. Thank you!

---

<div class="post-metadata">

**Author:** ![Kevin.Collins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.collins/32/13497_2.png) [@Kevin.Collins](https://forum.inductiveautomation.com/u/Kevin.Collins)\
**Post date:** [August 28, 2017, 1:33am UTC](https://forum.inductiveautomation.com/t/struggle-with-a-switch/15173/4 "2017-08-28T01:33:48Z")

</div>

Yeah, the reason the first example worked is that since you started with a String, it was able to cast the other integer values into that same (String) data type. As soon as you “set” the data type with that first value as an Integer, the usage of a String value broke it (since the system can’t convert “x” to an integer value automatically). Glad you got it working!
