Switch Bug?

Get help with using AutoHotkey and its commands and hotkeys
Rohwedder
Posts: 3663
Joined: 04 Jun 2014, 08:33
Location: Germany

Switch Bug?

02 Oct 2019, 10:20

Hallo,
this script can't handle my autohotkey 1.1.31.00 !

Code: Select all

q::
a = b
b = 5
Switch %a%
{
	Case 5: MsgBox,% A_LineNumber
}
burque505
Posts: 1398
Joined: 22 Jan 2017, 19:37

Re: Switch Bug?

02 Oct 2019, 10:43

Interesting. Hammered mine too, AHK stopped working completely. This works:

Code: Select all

global b = 5
global a = b

q::

Switch a
{
	Case 5: MsgBox,% A_LineNumber
}
return

Escape::ExitApp
But this does not, I suppose because b was assigned to a before b equals anything:

Code: Select all

global a = b
global b = 5


q::

Switch a
{
	Case 5: MsgBox,% A_LineNumber
}
return

Escape::ExitApp
And this does not work either:

Code: Select all

b = 5
a = b

q::

Switch a
{
	Case 5: MsgBox,% A_LineNumber
}
return

Escape::ExitApp
And this works:

Code: Select all

q::
global b = 5
global a = b
Switch a
{
	Case 5: MsgBox,% A_LineNumber
}
return
Escape::ExitApp
But this does not:

Code: Select all

q::
b = 5
a = b
Switch a
{
	Case 5: MsgBox,% A_LineNumber
}
return
Escape::ExitApp
teadrinker
Posts: 1904
Joined: 29 Mar 2015, 09:41
Contact:

Re: Switch Bug?

02 Oct 2019, 11:01

burque505 wrote: But this does not:

Code: Select all

q::
b = 5
a = b
Switch a
{
	Case 5: MsgBox,% A_LineNumber
}
return
Escape::ExitApp
This works properly, since a = "b".
Rohwedder wrote: this script can't handle my autohotkey 1.1.31.00 !
It seems that switch can't handle such syntax: Switch %a%
User avatar
boiler
Posts: 6602
Joined: 21 Dec 2014, 02:44

Re: Switch Bug?

02 Oct 2019, 11:10

Remember that a = b is equivalent to a := "b". You want a := b in order for a to contain 5.
burque505
Posts: 1398
Joined: 22 Jan 2017, 19:37

Re: Switch Bug?

02 Oct 2019, 11:23

As per @boiler, this works:

Code: Select all

q::
b := 5
a := b
Switch a
{
	Case 5: MsgBox,% A_LineNumber
}
return
Escape::ExitApp
However, this also works, so apparently if global, 'a = b' is not the same as 'a := "b"':

Code: Select all

q::
global b = 5
global a = b
Switch a
{
	Case 5: MsgBox,% A_LineNumber
}
return
Escape::ExitApp
And this works as well:

Code: Select all

q::
b = 5
a = %b%
Switch a
{
	Case 5: MsgBox,% A_LineNumber
}
return
Escape::ExitApp
teadrinker
Posts: 1904
Joined: 29 Mar 2015, 09:41
Contact:

Re: Switch Bug?

02 Oct 2019, 11:30

burque505 wrote: if global, 'a = b' is not the same as 'a := "b"
More about locals and globals wrote:A local or global variable may be initialized on the same line as its declaration by following it with := or = followed by any expression (the = operator behaves the same as := in declarations)
joefiesta
Posts: 383
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Switch Bug?

03 Oct 2019, 10:11

I don't understand this issue.

What are "SWITCH" and "CASE"? I can not find them in the documentation for AutoHotkey.
User avatar
boiler
Posts: 6602
Joined: 21 Dec 2014, 02:44

Re: Switch Bug?

03 Oct 2019, 10:17

joefiesta wrote:
03 Oct 2019, 10:11
What are "SWITCH" and "CASE"? I can not find them in the documentation for AutoHotkey.
Update to the latest version of AHK.
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Switch Bug?

03 Oct 2019, 10:18

Switch is been added in version 1.1.31.00 - September 28, 2019.
see here


EDIT: Boiler was faster than me.
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
joefiesta
Posts: 383
Joined: 24 Jan 2016, 13:54
Location: Pa., USA

Re: Switch Bug?

03 Oct 2019, 10:28

OMG! My bad. Wow, finally what is in some other languages a SELECT statement. Longer overdue!!! Awesome. I am so tired of writing first-grade style IF statements.

REXX uses SELECT. Why not SELECT? I think it describes what is happening much better than SWITCH. (Oh well... sure it's too late.)
User avatar
JoeWinograd
Posts: 1634
Joined: 10 Feb 2014, 20:00

Re: Switch Bug?

03 Oct 2019, 10:30

Hi joefiesta,

These two forum threads should be helpful:

test build v1.1.30.03-4+gdd14232
https://www.autohotkey.com/boards/viewtopic.php?t=63861

release v1.1.31.00
https://www.autohotkey.com/boards/viewtopic.php?p=294188

Regards, Joe
User avatar
boiler
Posts: 6602
Joined: 21 Dec 2014, 02:44

Re: Switch Bug?

03 Oct 2019, 10:53

joefiesta wrote:
03 Oct 2019, 10:28
REXX uses SELECT. Why not SELECT? I think it describes what is happening much better than SWITCH. (Oh well... sure it's too late.)
In other languages including REXX, Select is used where each Case has its own expression to be evaluated for selection, where Switch typically has one expression to be evaluated with various Case results of that expression. So in that sense, Switch is actually better describing what is happening than Select. Some languages like AutoIt have both, with that being the distinction between the two.

Return to “Ask For Help”

Who is online

Users browsing this forum: boiler, JAutohotkey, mikeyww and 35 guests