Home AMX Forum AMX General Discussion
Options

Switch/case compile error

Could somebody explain to me why this code compiles fine:
					
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

  • yuriyuri Junior Member
    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 ;) )
  • flcusatflcusat Junior Member
    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]  
    
    
  • Joe HebertJoe Hebert Junior Member
    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':
  • flcusatflcusat Junior Member
    Thanks Joe. My bad. I was in a hurry.
  • mpullinmpullin Obvious Troll Account, Marked for Deletion
    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.
  • Joe HebertJoe Hebert Junior Member
    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.
    }
    
    Good idea. I?ll have to remember that trick.
    mpullin wrote:
    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. :D
  • ericmedleyericmedley Senior Member - 3709 Posts
    this is one of those cases when SELECT-ACTIVE might be a good alternative.
  • yuriyuri Junior Member
    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. :D

    there IS no accent! :p

    btw. is it that bad?
  • Joe HebertJoe Hebert Junior Member
    yuri wrote:
    there IS no accent! :p

    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.
  • michux1michux1 Junior Member
    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.
Sign In or Register to comment.