Jump to content


Photo

similar to Switch in C


  • Please log in to reply
7 replies to this topic

#1 Azevedo

Azevedo
  • Members
  • 59 posts

Posted 20 May 2012 - 04:54 PM

Hey everyone!

Is there a command to handle a variable contents using a similar C command to Switch

Something like that:
switch(%A_ThisMenuItem%)
{
case 'option 1':
do something ...
break;
case 'option 2':
do something ...
break;
case 'option 3':
do something ...
break;
}

thanks

#2 Maestr0

Maestr0
  • Members
  • 649 posts

Posted 20 May 2012 - 05:26 PM

Like this?
switch("blah")

switch("test")

return



switch(param)

{

if param = test

{

 msgbox % param ": do this"

 return

}

else if param = test2

{

 msgbox % param ": do this"

 return

}

else

 msgbox % param ": do this"

return

}


#3 Azevedo

Azevedo
  • Members
  • 59 posts

Posted 20 May 2012 - 05:39 PM

Yeah but I'm looking for a built in, not a user created.

#4 Maestr0

Maestr0
  • Members
  • 649 posts

Posted 20 May 2012 - 05:42 PM

I don't understand what you want, maybe someone else can help.

#5 Guests

  • Guests

Posted 20 May 2012 - 05:54 PM

@Azevedo: there is no switch / case command in ahk. So you do have to build your own.
Search the forum, suggestion section, for case switch and you'll find a number of discussions.
It probably won't be added anytime soon.

#6 JSLover

JSLover
  • Members
  • 920 posts

Posted 20 May 2012 - 09:19 PM

I wrote this workaround 100 years ago...

Switch-Case.ahi
...or...(it's also included in Base.ahi)...

Base.ahi
...& yes, I know it's a "workaround", but it's the best I could do, since AutoHotkey does not have it built-in.

#7 Azevedo

Azevedo
  • Members
  • 59 posts

Posted 20 May 2012 - 11:09 PM

ok. thank you all!

#8 0x150--ISO

0x150--ISO
  • Members
  • 657 posts

Posted 22 May 2012 - 04:41 PM

Just a thought here. What about using the switch statement in js via com?
<!-- m -->http://www.w3schools...s/js_switch.asp<!-- m -->

Let me know if you need help with it..