Switch works but then the script exits and does NOT continue further.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

Switch works but then the script exits and does NOT continue further.

Post by jwinfl » 29 Sep 2022, 12:53

Thank you for looking at my post. I have no idea what is wrong.
Switch horz in the code below finds guiX and shows it in the first msgbox.
As soon as I press ok the script closes and never executes line 26, the second msgbox, or anything else I put after the switch.

Code: Select all

horz := "R", W := 300, H := 300
switch horz
{
	case "L":
		If W > a_screenwidth*.5
			guiX := 0
		else
			guiX := a_screenwidth*.25-(W*.5)
		return
	case "C":
		If W > a_screenwidth
			guiX := 0
		else
			guiX := a_screenwidth*.5-(W*.5)
		return
	case "R":
		If W > a_screenwidth*.5
			guiX := a_screenwidth-W
		else
			guiX := a_screenwidth*.75-(W*.5)
		If W > a_screenwidth
			guiX := 0
		msgbox % horz "`n" guiX "`nline..." A_linenumber
		return
}
msgbox % horz "`n" guiX "`nline..." A_linenumber
exitapp
Any help will be appreciated.
Thank you.


jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

Re: Switch works but then the script exits and does NOT continue further.

Post by jwinfl » 29 Sep 2022, 16:16

Thank you, I removed the returns and it works fine.
Prior to my original posting, I looked at https://www.autohotkey.com/docs/commands/Switch.htm several times and every example had a return and no where did it say it wasn't necessary.

User avatar
boiler
Posts: 16951
Joined: 21 Dec 2014, 02:44

Re: Switch works but then the script exits and does NOT continue further.

Post by boiler » 29 Sep 2022, 16:18

They had a return because they wanted to return at the end of each segment. You want yours to fall through to the subsequent command instead of returning. The second switch statement in their example doesn't have returns in each.

Post Reply

Return to “Ask for Help (v1)”