mmikeww / AHK-v2-script-converter

AHK v1 -> v2 script converter
https://autohotkey.com/boards/viewtopic.php?f=6&t=25100
The Unlicense
554 stars 43 forks source link

InputBox followed by MsgBox in Switch/Case statements #294

Open JoeWinograd opened 1 month ago

JoeWinograd commented 1 month ago

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 commented 1 month ago

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

JoeWinograd commented 1 month ago

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

Confirmed! Good call! Regards, Joe