case command?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
aaffe
Posts: 192
Joined: 16 Jan 2014, 04:23

case command?

16 Aug 2018, 08:19

One Question, perhaps I have forgotten About the possibility to do this:
Do we alreade have an case-command in ahk?
Like:

Code: Select all

case a in
1) do xyz
2) do zzz
Default) do Nothing
end case
User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: case command?

16 Aug 2018, 10:52

Hi aaffe,
There is no Case statement in AHK. You can simulate one with a series of If-Else statements. For example:

Code: Select all

If (Option="A")
{
  ; code for case A
}
Else
If (Option="B")
{
  ; code for case B
}
Else
If (Option="C")
{
  ; code for case C
}
Else
{
  ; code for case no match
}
Regards, Joe
gregster
Posts: 8990
Joined: 30 Sep 2013, 06:48

Re: case command?

16 Aug 2018, 12:33

Note that else if-statements don't have to be split into two separate lines. You can also do:

Code: Select all

Else If (Option="C")
But there needs to be a space between else and if
User avatar
JoeWinograd
Posts: 2198
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: case command?

16 Aug 2018, 13:04

Yep, that works, too, although I prefer the If statement on a separate line for readability. But, of course, that's a matter of coding style...both work...pick whatever you prefer. Thanks for pointing that out, gregster. Regards, Joe
aaffe
Posts: 192
Joined: 16 Jan 2014, 04:23

Re: case command?

17 Aug 2018, 01:18

Thank you. I know the Workaround with IFs, but I think a real case command would be better. But there isnt one as you wrote. Thanks for your answers!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Exies, JoeWinograd, mikeyww and 128 guests