Switch/case compile error
flcusat
Junior Member
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]
Comments
-
CASE '10' is indeed your problem...
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
) -
Thanks Yuri. But it didn't work. Here is the code with the local variable you suggested.
CASE 'NEWS/SPORTS=': { LOCAL_VAR FIX FIX=ATOI(DATA.TEXT) SWITCH(FIX) { 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 here the compiled error :---------- Starting NetLinx Compile - Version[2.4.0.1] [02-20-2008 07:39:52] ---------- 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 07:39:52]
-
You are switching off an integer now so you need to lose the quotes as yuri showed in his code example.
You need:
Case 1: thru Case 10:
instead of
Case '1': thru Case '10': -
Thanks Joe. My bad. I was in a hurry.
-
The problem with this is that when the compiler sees case '1' it thinks:
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.:SWITCH("'>',DATA.TEXT"){ CASE '>1': // stuff CASE '>2': // stuff CASE '>10': // stuff etc. }Since they all happen to be numbers in your situation, Joe's solution with atoi is simpler. -
Good idea. I?ll have to remember that trick.mpullin wrote:One solution I have used in the past is to append a character to every item, e.g.:SWITCH("'>',DATA.TEXT"){ CASE '>1': // stuff CASE '>2': // stuff CASE '>10': // stuff etc. }
Actually it was yuri?s solution, I just reiterated it. I think yuri?s Dutch accent threw Pedro off the first time.mpullin wrote:Since they all happen to be numbers in your situation, Joe's solution with atoi is simpler.
-
this is one of those cases when SELECT-ACTIVE might be a good alternative.
-
Joe Hebert wrote:Good idea. I’ll have to remember that trick.
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? -
Yours is no worse than everyone else. The only people that don?t have an accent are those of us that are from Shi-KAH-go, home of Da Bears.yuri wrote:there IS no accent!
btw. is it that bad? -
I had the same problem today and, after reading your posts, decided to reorder my case statements from longest to shortest
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.
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums