Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputBox followed by MsgBox in Switch/Case statements #294

Open
JoeWinograd opened this issue Sep 23, 2024 · 3 comments
Open

InputBox followed by MsgBox in Switch/Case statements #294

JoeWinograd opened this issue Sep 23, 2024 · 3 comments

Comments

@JoeWinograd
Copy link

V1:

Title:="Switch Case Test"
Input:=1
StartOver:
InputBox,Input,%Title%,Enter value or click Cancel to exit,,400,180,,,,,%Input%
If (ErrorLevel=1)
  ExitApp
Switch Input
{
  Case 1:
  MsgBox,262180,%Title%,Good Input=%Input%`n`nRun Again?

  Case 2:
  MsgBox,262180,%Title%,Good Input=%Input%`n`nRun Again?

  Default:
  MsgBox,262192,%Title%,Bad Input=%Input%
  Goto,StartOver
}
IfMsgBox,Yes
  Goto,StartOver
ExitApp

V2 (Converted):

Title:="Switch Case Test"
Input:=1
StartOver:
IB := InputBox("Enter value or click Cancel to exit", Title, "w400 h180", Input), Input := IB.Value, ErrorLevel := IB.Result="OK" ? 0 : IB.Result="CANCEL" ? 1 : IB.Result="Timeout" ? 2 : "ERROR"
If (ErrorLevel=1)
  ExitApp()
Switch Input
{
  Case 1:
  MsgBox("Good Input=" Input "`n`nRun Again?", Title, 262180)

  Case 2:
  MsgBox("Good Input=" Input "`n`nRun Again?", Title, 262180)

  Default:
  msgResult := MsgBox("Bad Input=" Input, Title, 262192)
  Goto("StartOver")
}
if (msgResult = "Yes")
  Goto("StartOver")
ExitApp()

V2 (Expected):

Title:="Switch Case Test"
Input:=1
StartOver:
IB := InputBox("Enter value or click Cancel to exit", Title, "w400 h180", Input), Input := IB.Value, ErrorLevel := IB.Result="OK" ? 0 : IB.Result="CANCEL" ? 1 : IB.Result="Timeout" ? 2 : "ERROR"
If (ErrorLevel=1)
  ExitApp()
Switch Input
{
  Case 1:
  msgResult := MsgBox("Good Input=" Input "`n`nRun Again?", Title, 262180)

  Case 2:
  msgResult := MsgBox("Good Input=" Input "`n`nRun Again?", Title, 262180)

  Default:
  msgResult := MsgBox("Bad Input=" Input, Title, 262192)
  Goto("StartOver")
}
if (msgResult = "Yes")
  Goto("StartOver")
ExitApp()

Enter a value a second time in the InputBox to get the error. Without putting "msgResult:=" in front of each MsgBox in the Switch/Case statements, you get this error:

SwitchCaseMsgBox_ConverterBug

Regards, Joe

@Banaanae
Copy link
Collaborator

Turns out the reason this doesn't convert properly is because there's a newline between Case and MsgBox :)
Should be easy fix

@JoeWinograd
Copy link
Author

Turns out the reason this doesn't convert properly is because there's a newline between Case and MsgBox :)

Confirmed! Good call! Regards, Joe

Banaanae added a commit that referenced this issue Oct 3, 2024
added f tests for #294 #295 #296 #298 #299 #300 #301
cleanup return tests
@Banaanae
Copy link
Collaborator

Banaanae commented Nov 17, 2024

The issue is on this line

} else if (RegExMatch(LineContSect, "i)^\s*MsgBox([,\s]|$)")) {

The regex only checks for msgboxs with newlines in front, so case is unintentionally working correctly

MsgBox, Not this one

if false {
; False
} else MsgBox, 4,, This One

IfMsgBox, Yes
	MsgBox, Correct one

It might be worth adding the var to all msgbox with 40 lines, as there'll be lots of issues with conditional msgboxes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants