Switch/case compile error
flcusat
Posts: 309
Could somebody explain to me why this code compiles fine:
And this one doesn't:
Here is the error at compile:
CASE 'NEWS/SPORTS=': { SWITCH(DATA.TEXT) { CASE'0': { QUE_CMD("$FA,$A6,$00,$CA,$FF,$FF") //CNN } CASE'1': { QUE_CMD("$FA,$A6,$01,$63,$FF,$FF") //CNBC } CASE'2': { QUE_CMD("$FA,$A6,$01,$5E,$FF,$FF") //CSPAN } CASE'3': { QUE_CMD("$FA,$A6,$01,$5F,$FF,$FF") //CSPAN2 } CASE'4': { QUE_CMD("$FA,$A6,$00,$F3,$FF,$FF") //COURTV } CASE'5': { QUE_CMD("$FA,$A6,$01,$64,$FF,$FF") //MSNBC } CASE'6': { QUE_CMD("$FA,$A6,$01,$68,$FF,$FF") //FOXNEWS } CASE'7': { QUE_CMD("$FA,$A6,$01,$6A,$FF,$FF") //TWC } CASE'8': { QUE_CMD("$FA,$A6,$00,$CE,$FF,$FF") //ESPN } CASE'9': { QUE_CMD("$FA,$A6,$00,$D1,$FF,$FF") //ESPN2 } (* CASE'10': { QUE_CMD("$FA,$A6,$02,$78,$FF,$FF") //SUN SPORTS } *) } }
And this one doesn't:
CASE 'NEWS/SPORTS=': { SWITCH(DATA.TEXT) { CASE'0': { QUE_CMD("$FA,$A6,$00,$CA,$FF,$FF") //CNN } CASE'1': { QUE_CMD("$FA,$A6,$01,$63,$FF,$FF") //CNBC } CASE'2': { QUE_CMD("$FA,$A6,$01,$5E,$FF,$FF") //CSPAN } CASE'3': { QUE_CMD("$FA,$A6,$01,$5F,$FF,$FF") //CSPAN2 } CASE'4': { QUE_CMD("$FA,$A6,$00,$F3,$FF,$FF") //COURTV } CASE'5': { QUE_CMD("$FA,$A6,$01,$64,$FF,$FF") //MSNBC } CASE'6': { QUE_CMD("$FA,$A6,$01,$68,$FF,$FF") //FOXNEWS } CASE'7': { QUE_CMD("$FA,$A6,$01,$6A,$FF,$FF") //TWC } CASE'8': { QUE_CMD("$FA,$A6,$00,$CE,$FF,$FF") //ESPN } CASE'9': { QUE_CMD("$FA,$A6,$00,$D1,$FF,$FF") //ESPN2 } CASE'10': { QUE_CMD("$FA,$A6,$02,$78,$FF,$FF") //SUN SPORTS } } }
Here is the error at compile:
---------- Starting NetLinx Compile - Version[2.4.0.1] [02-20-2008 06:36:19] ---------- C:\Documents and Settings\Owner.Gateway\My Documents\AMX\Modules\DIRECTV\DIRECTV_Comm.axs ERROR: (0): C10580: Internal Error: Major system error occurred during code generation C:\Documents and Settings\Owner.Gateway\My Documents\AMX\Modules\DIRECTV\DIRECTV_Comm.axs - 1 error(s), 0 warning(s) NetLinx Compile Complete [02-20-2008 06:36:19]
0
Comments
Strange thing is that when you change CASE '10' to CASE '1' (which already exists), your code compiles fine... instead, you should get a 'DUPLICATE CASE' error.
fix it like this:
LOCAL_VAR test
test = ATOI(DATA.TEXT)
SWITCH(test)
{
CASE 1:
{
//etc
}
}
(but you probably worked that out yourself )
And here the compiled error :
You need:
Case 1: thru Case 10:
instead of
Case '1': thru Case '10':
Ok, these are all going to be single characters!
But then when it sees '10' it thinks:
That's not a value of the type I was expecting, so I'm going to take a nap. Helpful error message? Nah, too tired. Zzz.
You can do all integer, all character, or all multi-character strings, but don't try to mix & match. One solution I have used in the past is to append a character to every item, e.g.: Since they all happen to be numbers in your situation, Joe's solution with atoi is simpler.
Actually it was yuri?s solution, I just reiterated it. I think yuri?s Dutch accent threw Pedro off the first time.
there IS no accent!
btw. is it that bad?
ie.
CASE 'ERR':
CASE 'OK':
CASE '32':
CASE '16':
CASE '8':
CASE '4':
CASE '3':
CASE '2':
CASE '1':
...you get the picture. Worked like a charm and I didn't have to use ATOI (especially because 'OK' and 'ERR' kind of want to be ascii.