Home AMX User Forum NetLinx Studio

Case with '

Let's say I have some rooms, named the following:
Theater
John's Room
Media Room

Now let's say I want to do a switch/case block to take an action depending on the room name. How do I deal with the apostrophe? This won't compile:
switch(sRoom[sTP_Session[GET_LAST(arrTP)].currRoom].name){
		    case "'Theater'": SEND_COMMAND vdvAMP_THEATER, "'SURROUND?'";
			 SEND_COMMAND BUTTON.INPUT.DEVICE, 'PPON-Surround_Mode';
		    case "'John',$27,'s Room'": SEND_COMMAND vdvAMP_JOHN_ROOM, "'SURROUND?'";
			 SEND_COMMAND BUTTON.INPUT.DEVICE, 'PPON-Surround_Mode';
		    case "'Media Room'": SEND_COMMAND vdvAMP_MEDIA_ROOM, "'SURROUND?'";
			 SEND_COMMAND BUTTON.INPUT.DEVICE, 'PPON-Surround_Mode';
		    default: break; // other rooms
		}

Anyone have any ideas for making this work? I realize one could just use select/active, but I want to know if it is possible to do it with switch/case. Would make a nice brain bender for an 11 am coffee break.

Comments

  • TurnipTruckTurnipTruck Posts: 1,485
    Could you base your conditional on the first few characters of the room name before the ' ??
  • mpullinmpullin Posts: 949
    Could you base your conditional on the first few characters of the room name before the ' ??
    Let's say there is also a room John's Closet, so no. :(
  • Joe HebertJoe Hebert Posts: 2,159
    mpullin wrote: »
    Let's say I have some rooms, named the following:
    Theater
    John's Room
    Media Room

    Now let's say I want to do a switch/case block to take an action depending on the room name. How do I deal with the apostrophe?
    This won?t work?
    CASE ?John??s Room?:
    
  • ericmedleyericmedley Posts: 4,177
    Joe Hebert wrote: »
    This won’t work?
    CASE ‘John’’s Room’:
    

    What if you just added the hex asci chars up and did a case by that?

    john's = $64,$6F,$68,$6E,$27,$73.

    add them up before going into the switch / case

    (I know, I'm getting way to far in...)

    Actually this might be a good situation for using a Select Active rather than a Switch Case.
  • mpullinmpullin Posts: 949
    Joe Hebert wrote: »
    CASE ?John??s Room?:
    
    It compiles... This would be a good answer if it works, tests are required... I didn't know '' was a legit escape for an apostrophe in NetLinx.
  • a_riot42a_riot42 Posts: 1,624
    mpullin wrote: »
    It compiles... This would be a good answer if it works, tests are required... I didn't know '' was a legit escape for an apostrophe in NetLinx.

    Why use text at all? You should have a constant for each room that is an integer and then check that. You are asking for trouble (and already received some) using text to do this.
    The escape for ' is ' not ".
    Paul
Sign In or Register to comment.