Home AMX User Forum NetLinx Studio

Switch..Case - Bug?

I'm running the latest Netlinx Studio 2.4.0.129

This doesn't compile. "Major system error occurred during code generation":

SWITCH(Cmd)
{
CASE '.': SEND_STRING dvDevice, "'Dot'"
CASE 'Test': SEND_STRING dvDevice, "'Test'"
}

But this does:

SWITCH(Cmd)
{
CASE 'Test': SEND_STRING dvDevice, "'Test'"
CASE '.': SEND_STRING dvDevice, "'Dot'"
}

Just the same two CASE statements in a different order. Any idea what's going on here? Bug in Netlinx Studio perhaps?

I searched the forums and couldn't find anything on it, so I thought I would ask. Maybe it's related to the lower 8-bit bug/feature with switch..case statements. I read elsewhere on the forum of a similar problem with the order of CASE values beyond 255.

Just got me curious, so I thought I would see if anyone had an answer to offer.

--Eric

Comments

  • DHawthorneDHawthorne Posts: 4,584
    It's my understanding CASE tags in a SWITCH need to be CHAR values, and constants. Even though your second example might compile, it's only coincidental that it actually works. Use SELECT...ACTIVE instead if working with CHAR arrays. NetLinx studio Help might say string literals are OK, but it does not seem to actually be the case. I've also seen reports that you need to put them in order - if you have "CASE 2:" ahead of "CASE 1:," for example, it may not work. I don't think this is a bug in the program as much as a documentation error, though the compiler error message sure could be more helpful.
  • mpullinmpullin Posts: 949
    I have not had any problems with switching on char arrays. For instance the following has always worked.
    DEFINE_FUNCTION TP_GoTo (CHAR PAGE[]){
        SEND_COMMAND BUTTON.INPUT.DEVICE, "'PAGE-',PAGE"
        switch(PAGE){
    	case 'ARQ':{ // arq interface
    	    // do ARQ stuff
    	}
    	case 'VRQ':{ // vrq interface
    	    // do VRQ stuff
    	}
    	case 'Tivo Control':{ // Tivo control
    	    // do Tivo Stuff
    	}
        }
    }
    
    To original poster: How is Cmd defined in your program?

    Here's another thought... Maybe the compiler is having an issue with the single character being used in the same context as the array.
    Try this instead:
    SWITCH("Cmd,'ABC'")
    {
    CASE '.ABC': SEND_STRING dvDevice, "'Dot'"
    CASE 'TestABC': SEND_STRING dvDevice, "'Test'"
    }
    
  • DHawthorne wrote:
    I've also seen reports that you need to put them in order - if you have "CASE 2:" ahead of "CASE 1:," for example, it may not work.

    The above is not true...
    ekeppel wrote:
    SWITCH(Cmd)
    {
    CASE '.': SEND_STRING dvDevice, "'Dot'"
    CASE 'Test': SEND_STRING dvDevice, "'Test'"
    }

    What is happening is the Compiler sees the '.' in the first CASE evaluation and registers single CHAR values for the SWITCH..CASE, thus any CASE after that MUST be a single CHAR value. A STRING after that will cause an error because it is not a single CHAR value.

    I'm not sure if this is meant to be this way...or it is a bug, but thats the explaination why your example above doesn't compile.
    mpullin wrote:
    To original poster: How is Cmd defined in your program?

    even If Cmd is defined as a string, if the string only has a length of 1.(in this case '.'), it will still register a single CHAR value.
Sign In or Register to comment.