AHK-v2-script-converter icon indicating copy to clipboard operation
AHK-v2-script-converter copied to clipboard

Converting of labels

Open dmtr99 opened this issue 3 years ago • 1 comments

in V2, labels must sometimes be converted to functions. does this means that we should start this function with global?

example: Process example 3 ( almost working) https://www.autohotkey.com/docs/commands/Process.htm

#z:: ; Win+Z hotkey
WinGet, active_pid, PID, A
WinGetTitle, active_title, A
Gui, 5:Add, Text,, Press ESCAPE to cancel, or double-click a new`npriority level for the following window:`n%active_title%
Gui, 5:Add, ListBox, vMyListBox gMyListBox r5, Normal|High|Low|BelowNormal|AboveNormal
Gui, 5:Add, Button, default, OK
Gui, 5:Show,, Set Priority
return

5GuiEscape:
5GuiClose:
Gui, Destroy
return

MyListBox:
if (A_GuiEvent != "DoubleClick")
    return
; else fall through to the next label:
5ButtonOK:
GuiControlGet, MyListBox
Gui, Destroy
Process, Priority, %active_pid%, %MyListBox%
if ErrorLevel
    MsgBox Success: Its priority was changed to "%MyListBox%".
else
    MsgBox Error: Its priority could not be changed to "%MyListBox%".
return

=>

#z:: ; Win+Z hotkey
{ ; V1toV2: Added bracket
; add global here ???
active_pid := WinGetPID("A")
active_title := WinGetTitle("A")
oGui5 := Gui()
oGui5.OnEvent("Close", _5GuiEscape)
oGui5.OnEvent("Escape", _5GuiEscape)
oGui5.Add("Text", , "Press ESCAPE to cancel, or double-click a new`npriority level for the following window:`n" . active_title)
ogcMyListBox := oGui5.Add("ListBox", "vMyListBox  r5", ["Normal", "High", "Low", "BelowNormal", "AboveNormal"])
ogcMyListBox.OnEvent("DoubleClick", MyListBox)
ogcButtonOK := oGui5.Add("Button", "default", "OK")
ogcButtonOK.OnEvent("Click", _5ButtonOK)
oGui5.Title := "Set Priority"
oGui5.Show()
return
} ; Added bracket before function

_5GuiEscape(*)
{ ; V1toV2: Added bracket
; add global here ???
_5GuiClose:
oGui5.Destroy()
return
} ; V1toV2: Added Bracket before label

MyListBox(*)
{ ; V1toV2: Added bracket
; add global here ???
if (A_GuiEvent != "DoubleClick")
    return
; this is wrongly converting, I know, but it is hard to follow the code flow, maybe add an option to not close the brackets if the return is unclear, or add a sentense that will give an error and tell the user to verify the code here indicate an unclear conversion?
} ; V1toV2: Added Bracket before label
; else fall through to the next label:
_5ButtonOK(*)
{ ; V1toV2: Added bracket
; add global here ???
MyListBox := ogcMyListBox.Text
oGui5.Destroy()
ErrorLevel := ProcessSetPriority(MyListBox, active_pid)
if ErrorLevel
    MsgBox("Success: Its priority was changed to `"" MyListBox "`".")
else
    MsgBox("Error: Its priority could not be changed to `"" MyListBox "`".")
return
} ; V1toV2: Added bracket in the end

dmtr99 avatar Sep 14 '21 21:09 dmtr99

yes labels are global scope in v1, so i think you should def make the converted funcs global

mmikeww avatar Sep 15 '21 00:09 mmikeww