Home AMX User Forum NetLinx Studio

Switch...Case problem

jjamesjjames Posts: 2,908
Here's my switch / case:
switch(s_splitOutput[2])
{
	case '0'         	:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E0"
	case '1'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E1"
	case '2'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E2"
	case '3'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E3"
	case '4'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E4"
	case '5'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E5"
	case '6'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E6"
	case '7'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E7"
	case '8'         	:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E8"
	case '9'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E9"
	
	case 'ENTER'		:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A0"
	case 'INFO'		   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A1"
	case 'ACTIVE'	   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A2"
	case 'LIST'		   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A3"
	case 'BACK'		   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A4"
	case 'DASH'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A5"
	case 'SELECT'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$C3"
	case 'POWER_ON'   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$C5"
	case 'PAUSE'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B0"
	case 'REWIND'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B1"
	case 'PLAY'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B2"
	case 'STOP'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B3"
	case 'FFWD'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B4"
	case 'RECORD'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B5"
	case 'REPLAY'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B6"
	case 'ADVANCE'    :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B7"
	case 'RED'        :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EA"
	case 'YELLOW'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EB"
	case 'GREEN'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EC"
	case 'BLUE'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$ED"
	case 'MENU'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$F7"
	case 'FORMAT'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$F8"
	case 'POWER_OFF'  :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D0"
	case 'CHAN+'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D1"
	case 'CHAN-'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D2"
	case 'GUIDE'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D3"
	case 'EXIT'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D4"
	case 'POWER'		:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D5"
	case 'PREV'			:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D6"
	case 'RIGHT'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9A"
	case 'LEFT'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9B"
	case 'UP'         :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9C"
	case 'DOWN'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9D"
}

Commenting out the numerics allows it to compile. With it in there I get the following message:
ERROR: (0): C10580: Internal Error: Major system fubar occurred during code generation.
Okay - not really, but I do get a Major system error. What give? Doesn't matter where the numerics in the switch/case are, or even using decimal or hex values in their place.

Edit - sorry for the lines not lining up . . . my tab/spacing settings sometimes freaks out when copying & pasting it seems.

Comments

  • jjamesjjames Posts: 2,908
    Making it a SELECT/ACTIVE fixes the problem.

    I seem to remember a bug with the SWITCH/CASE and numerics - any one have an idea?
  • Spire_JeffSpire_Jeff Posts: 1,917
    Might it be that it is treating the numbers as chars, not strings and the others are treated as strings? Try " " around the numbers maybe?

    Jeff
  • jjamesjjames Posts: 2,908
    Spire_Jeff wrote: »
    Try " " around the numbers maybe?
    Yup, tried that as well. No love....

    I'm sticking with the SELECT/ACTIVE which seems to be working.
  • truetrue Posts: 307
    Tabbing your colon isn't very readable...standard practice is to put it in front of your case. This said...

    discussion nullified and lulz kept intact
  • Joe HebertJoe Hebert Posts: 2,159
    jjames wrote: »
    Here's my switch / case:
    switch(s_splitOutput[2])
    {
    	case '0'         	:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E0"
    	case '1'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E1"
    	case '2'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E2"
    	case '3'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E3"
    	case '4'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E4"
    	case '5'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E5"
    	case '6'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E6"
    	case '7'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E7"
    	case '8'         	:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E8"
    	case '9'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E9"
    	
    	case 'ENTER'		:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A0"
    	case 'INFO'		   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A1"
    	case 'ACTIVE'	   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A2"
    	case 'LIST'		   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A3"
    	case 'BACK'		   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A4"
    	case 'DASH'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A5"
    	case 'SELECT'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$C3"
    	case 'POWER_ON'   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$C5"
    	case 'PAUSE'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B0"
    	case 'REWIND'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B1"
    	case 'PLAY'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B2"
    	case 'STOP'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B3"
    	case 'FFWD'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B4"
    	case 'RECORD'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B5"
    	case 'REPLAY'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B6"
    	case 'ADVANCE'    :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B7"
    	case 'RED'        :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EA"
    	case 'YELLOW'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EB"
    	case 'GREEN'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EC"
    	case 'BLUE'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$ED"
    	case 'MENU'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$F7"
    	case 'FORMAT'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$F8"
    	case 'POWER_OFF'  :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D0"
    	case 'CHAN+'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D1"
    	case 'CHAN-'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D2"
    	case 'GUIDE'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D3"
    	case 'EXIT'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D4"
    	case 'POWER'		:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D5"
    	case 'PREV'			:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D6"
    	case 'RIGHT'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9A"
    	case 'LEFT'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9B"
    	case 'UP'         :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9C"
    	case 'DOWN'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9D"
    }
    

    Commenting out the numerics allows it to compile. With it in there I get the following message:
    ERROR: (0): C10580: Internal Error: Major system fubar occurred during code generation.
    

    I think it will compile if you move the single characters 0-9 to the bottom of the switch (after DOWN.)
  • jjamesjjames Posts: 2,908
    true wrote: »
    Tabbing your colon isn't very readable...standard practice is to put it in front of your case.
    Who's practice? Yours? The "standard practice" group you made up on Google? Beauty is in the eye of the beholder, not by a group of people agreeing on something.

    That said, I believe your assessment may be half wrong since moving to the end worked. Thanks Joe!
  • truetrue Posts: 307
    jjames wrote: »
    Who's practice?

    K&R
    GNU / Gnits
    Large organizations known for software (Microsoft, Google, etc)
    Working professional programmers
    List goes on - search for it?

    Some examples
    http://en.wikipedia.org/wiki/Switch_statement

    But this thread wasn't originally about this, was it? Not sure why you took such offense and had to fire off such a response. Regardless, if you think code "beauty" is in the eye of the beholder and needs to be defended, then thankfully I don't work with you, and you may want to consider not posting terrible code samples when asking for help. For what it's worth, your intense data duplication in that switch makes me chuckle.

    Back on topic, thanks Joe Herbert, starting with a two-or-more character string does fix the problem (at least as far as compiling it goes). Thanks for pointing that out.
  • Jimweir192Jimweir192 Posts: 502
    Don't you need the longest value of the case at the top, I seem to remember a bug that caused issues with Switch..Case if you started with the lowest value and the cases exceeded a single digit.

    ie
    switch(s_splitOutput[2])
    {
            case 'POWER_OFF'  :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D0"
    	case '0'         	:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E0"
    	case '1'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E1"
    	case '2'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E2"
    	case '3'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E3"
    	case '4'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E4"
    	case '5'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E5"
    	case '6'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E6"
    	case '7'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E7"
    	case '8'         	:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E8"
    	case '9'          :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$E9"
    	
    	case 'ENTER'		:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A0"
    	case 'INFO'		   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A1"
    	case 'ACTIVE'	   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A2"
    	case 'LIST'		   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A3"
    	case 'BACK'		   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A4"
    	case 'DASH'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$A5"
    	case 'SELECT'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$C3"
    	case 'POWER_ON'   :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$C5"
    	case 'PAUSE'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B0"
    	case 'REWIND'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B1"
    	case 'PLAY'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B2"
    	case 'STOP'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B3"
    	case 'FFWD'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B4"
    	case 'RECORD'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B5"
    	case 'REPLAY'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B6"
    	case 'ADVANCE'    :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$B7"
    	case 'RED'        :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EA"
    	case 'YELLOW'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EB"
    	case 'GREEN'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$EC"
    	case 'BLUE'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$ED"
    	case 'MENU'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$F7"
    	case 'FORMAT'     :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$F8"
    	case 'CHAN+'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D1"
    	case 'CHAN-'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D2"
    	case 'GUIDE'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D3"
    	case 'EXIT'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D4"
    	case 'POWER'		:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D5"
    	case 'PREV'			:s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$D6"
    	case 'RIGHT'      :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9A"
    	case 'LEFT'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9B"
    	case 'UP'         :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9C"
    	case 'DOWN'       :s_outgoingString = "$FA,$A5,ATOI(s_splitOutput[1]),$9D"
    }
    

    Sorry, just bothered to read Joe's post which answered this anyway.
  • jjamesjjames Posts: 2,908
    true wrote: »
    But this thread wasn't originally about this, was it?
    Nope, which is why I'm still confused as to why you'd even say something in the first place. ;)
    true wrote: »
    Regardless, if you think code "beauty" is in the eye of the beholder and needs to be defended, then thankfully I don't work with you....
    The feeling is mutual.
    true wrote: »
    ...and you may want to consider not posting terrible code samples when asking for help. For what it's worth, your intense data duplication in that switch makes me chuckle.
    My apologies Grand Master. Will you please teach me? I'm dying to learn from someone who feels AMX is junk and wants to view their Linux code for the touch panels in order to start his own control system company to compete with AMX (now that makes me chuckle.) Hurry up will you? I'm tired of your pompous "ace" posts.

    By the way - how's that song lyric go? Oh yeah, "first came an action and then a reaction, but you can't switch em' round for your own satisfaction"
  • truetrue Posts: 307
    jjames wrote: »
    ...and wants to view their Linux code for the touch panels in order to start his own control system company...

    lol

    I should come up with a term for this AMX dealer and programmer "someone will steal your stuff and make a company from it" mentality. (fwiw, AMX is obligated to give me, and you, source for certain components, such as the Linux kernel.)
  • jjamesjjames Posts: 2,908
    true wrote: »
    lol

    I should come up with a term for this AMX dealer and programmer "someone will steal your stuff and make a company from it" mentality. (fwiw, AMX is obligated to give me, and you, source for certain components, such as the Linux kernel.)
    For what reason? To stand on the shoulders of giants? Your "entitlement" complex is quite annoying.
  • truetrue Posts: 307
    Because it is a part of the license that they implicitly agreed to by distributing software licensed under the GPLv2. It isn't my complex, it is AMX breaking the GPL.

    You wouldn't like it if someone stole your code and distributed it without permission, right? That's copyright infringement. AMX is doing just that and you seem to be fine thinking I have a complex for it.

    Do some reading, it might do you some good:
    http://www.gnu.org/licenses/gpl-2.0.txt

    I know you can read, but if you have comprehension issues, have someone explain Section 3 to you.

    Are you a complete idiot? Sources to the kernel, Busybox, etc. isn't source to vtg, the actual touchpanel software.
  • jjamesjjames Posts: 2,908
    true wrote: »
    Because it is a part of the license that they implicitly agreed to by distributing software licensed under the GPLv2. It isn't my complex, it is AMX breaking the GPL.

    Do some reading, it might do you some good:
    http://www.gnu.org/licenses/gpl-2.0.txt

    I know you can read, but if you have comprehension issues, have someone explain Section 3 to you.
    Blah blah blah - take them to court and shut up about it, eh?
    true wrote: »
    Are you a complete idiot?
    I love you.
  • the8thstthe8thst Posts: 470
    Joe Hebert wrote: »
    I think it will compile if you move the single characters 0-9 to the bottom of the switch (after DOWN.)

    That is my experience with Switch...Case. single characters always go after multiple character cases, although I don't think you need to have the longest case first.
  • PhreaKPhreaK Posts: 966
    *avoids temptation to get involved in the excrement flinging*

    If I remember correctly a switch...case in NetLinx will cast all case values to the smallest type that will preserve the value of the first case statment. For example:
    x = 5
    
    switch (x) {
        case 1: // this will cast everything to a char...
        case 261: // which means this will trigger,
        case 5: // and this won't
    }
    
  • PhreaKPhreaK Posts: 966
    a_riot42 wrote: »
    If having an opinion about code on a code forum is excrement flinging, then we are all covered in it.

    Very true, and well put - the comment wasn't necessarily focused at your post though.

    P.S. regarding the TP firmware, if it is GPLv2 true is absolutely 100% within his rights to request, and is entitled to the source of any components which fall under that license, nothing complex about it.
Sign In or Register to comment.