Switch/Case with case more than one CaseValue. Topic is solved

Discuss the future of the AutoHotkey language
User avatar
aseiot
Posts: 33
Joined: 05 Mar 2017, 04:25

Switch/Case with case more than one CaseValue.

19 Aug 2019, 18:02

Document said:

Code: Select all

Switch [SwitchValue]
{
Case CaseValue1:
    Statements1
Case CaseValue2a, CaseValue2b:
    Statements2
Default:
    Statements3
}
And I tried the code:

Code: Select all

Switch 1
{
	;Case 1,2: Msgbox("2")				; More than one CaseValue, Err: This line does not contain a recognized action.
	;Case 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20:	Msgbox("2")		; And more, Err: Function calls require a space or "(".  Use comma only between parameters.
	;Case (1,2): Msgbox("2")				; Equal to Case 2:
	Case 1: Msgbox("1")
}
Could someone to point out the correct syntax, thanks.
User avatar
JoeWinograd
Posts: 1325
Joined: 10 Feb 2014, 20:00

Re: Switch/Case with case more than one CaseValue.

19 Aug 2019, 20:12

Seems to me that it's a bug. As you posted, the Switch doc says that this is a valid Case statement:

Case CaseValue2a, CaseValue2b:

It also says that each Case statement may have up to 20 values, so, of course, two should work fine. But the following simple script that follows the syntax above shows that it doesn't work:

Code: Select all

sv:="b"
Switch sv
{
Case "a":
  MsgBox("Case-a: sv=" . sv)
Case "b", "c":
  MsgBox("Case-bc: sv=" . sv)
Default:
  MsgBox("Default: sv=" . sv)
}
It produces this error dialog:

Switch-Case-V2-bug.png
Switch-Case-V2-bug.png (23.88 KiB) Viewed 620 times

The script works fine when the second Case statement is:

Case "b":

I suggest that you file a bug report here:

https://www.autohotkey.com/boards/viewforum.php?f=14

Regards, Joe
User avatar
aseiot
Posts: 33
Joined: 05 Mar 2017, 04:25

Re: Switch/Case with case more than one CaseValue.  Topic is solved

11 Sep 2019, 09:58

The problem had been fixed in the latest git version

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 12 guests