Can I use a select case statement within my macro?

Can I use a select case statement within my macro?
none 0.0 0

Is it possible to perform a case statement on a two letter char variable?

i.e.

case “AA”
case “AB”

1 Like

Hi @jnorris,

Since the “case” within a select case statement must be a constant, it might be easier to compare a two character string using an if statement instead. Here is an example:

macro_command main()
char aa[2] = "AA"
char bb[2] = "BB"
char ab[2] = "AB"
bool compare[10] = {0,0,0,0,0,0,0,0,0,0}

char in[2] = {0,0}

GetData(in[0], "Local HMI" LW, 0, 2) // Get data for testing
compare[0] = StringCompareNoCase(aa[0], in[0]) // compare input to "AA"
compare[1] = StringCompareNoCase(bb[0], in[0]) // compare input to "BB"
compare[2] = StringCompareNoCase(ab[0], in[0]) // compare input to "AB"

if compare[0] then
	// input == aa
else if compare[1] then
	// input == bb
else if compare[2] then
	// input == ab
end if

end macro_command
1 Like

Awesome, thanks Brendon.

1 Like