# Type Conversion error on switch statement

**URL:** <https://forum.inductiveautomation.com/t/type-conversion-error-on-switch-statement/19066>\
**Category:** Ignition\
**Tags:** ignition78\
**Created:** [August 2, 2018, 8:18am UTC](https://forum.inductiveautomation.com/t/type-conversion-error-on-switch-statement/19066 "2018-08-02T08:18:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anwesha\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@Anwesha\_Gupta](https://forum.inductiveautomation.com/u/Anwesha_Gupta)\
**Post date:** [August 2, 2018, 8:18am UTC](https://forum.inductiveautomation.com/t/type-conversion-error-on-switch-statement/19066/1 "2018-08-02T08:18:35Z")

</div>

Hello All,  
I am trying to use a template repeater which has a component ‘Status’ (Integer). I am using the following code to drive the ‘Status’ .

switch(  
{AllProjectsSite.SiteName},  
‘PoT’,  
‘Broxburn’,  
‘TynemouthA’,  
‘TynemouthB’,  
(if({AllProjectsSite.PoTBMSChldCnt}!={AllProjectsSite.PoTBMSTtlChldrnAvl},‘0’,‘1’)),  
(if({AllProjectsSite.BroxburnBMSChldCnt}!={AllProjectsSite.BroxburnBMSTtlChldrnAvl},‘0’,‘1’)),  
(if({AllProjectsSite.TynemouthABMSChldCnt}!={AllProjectsSite.TynemouthABMSTtlChldrnAvl},‘0’,‘1’)),  
(if({AllProjectsSite.TynemouthBBMSChldCnt}!={AllProjectsSite.TynemouthBBMSTtlChldrnAvl},‘0’,‘1’)),  
forceQuality(“0”,192)

Where I am trying to switch on Sitename (String).  
Then I am comparing using If statement in the Switch return, to get a 0 or 1 which drives the Status bit.  
Since I am switching on a string, the output (return) of the If statements wont accept 0,1 as output.(it gave me error). When I put the 0 or 1 in quotes it accepts it without any error.

But when I look at the screen , it gives me a type conversion error. See screen shot.

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/3/353ca37d97b7f11a8d38facd2fa27e62d4bb5cae.PNG)

I assume this is the type conversion error on the screen.  
And I am wondering how to sort this problem out.  
Can anyone please help?

---

<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:** [August 2, 2018, 2:43pm UTC](https://forum.inductiveautomation.com/t/type-conversion-error-on-switch-statement/19066/2 "2018-08-02T14:43:43Z")

</div>

You can simplify your switch statement like this:

```auto
toInt(
	switch(
		{AllProjectsSite.SiteName},
		'PoT',
		'Broxburn',
		'TynemouthA',
		'TynemouthB',
		{AllProjectsSite.PoTBMSChldCnt}!={AllProjectsSite.PoTBMSTtlChldrnAvl},
		{AllProjectsSite.BroxburnBMSChldCnt}!={AllProjectsSite.BroxburnBMSTtlChldrnAvl},
		{AllProjectsSite.TynemouthABMSChldCnt}!={AllProjectsSite.TynemouthABMSTtlChldrnAvl},
		{AllProjectsSite.TynemouthBBMSChldCnt}!={AllProjectsSite.TynemouthBBMSTtlChldrnAvl},
		0
	)
)

```

`forceQuality` on a static value of 0 won’t do anything. The important thing to know about the switch/case statements is that they attempt to return the type of the default/fallback value. 1/0 and boolean true/false typecast back and forth pretty much transparently, but in this case to ensure that the final output is an integer you can wrap the entire statement in a `toInt`.

---

<div class="post-metadata">

**Author:** ![Anwesha\_Gupta](https://avatars.discourse-cdn.com/v4/letter/a/53a042/32.png) [@Anwesha\_Gupta](https://forum.inductiveautomation.com/u/Anwesha_Gupta)\
**Post date:** [August 10, 2018, 8:45am UTC](https://forum.inductiveautomation.com/t/type-conversion-error-on-switch-statement/19066/3 "2018-08-10T08:45:49Z")

</div>

Thank you.

This seems to have sorted the issue out.

Regards  
Anwesha.
