Reputation: 281
Im attempting to make a macro using AutoHotKey and im trying to have a loop create as many GUI's as the user specifies, the only problem is that when "return" is called after the "OK:" line, the GUI exits the loop as well as the current GUI. Therefore the loop is only running the first time before the entire app is exited?
My code is below, any help would be greatly appreciated! thanks!
n = 0
Loop:
{
n := n + 1
Gui, Add, Button, x1 y174 w110 h40 gOK, Button
Gui, Add, Text, x1 y34 w90 h20 , City #%n% Name:
Gui, Add, Edit, x91 y34 w200 h20 vCity, Edit
Gui, Add, Text, x1 y84 w60 h20 , Farm 1
Gui, Add, Edit, x61 y84 w70 h20 vFarm1, Edit
Gui, Add, Text, x1 y134 w60 h20 , Farm 2
Gui, Add, Edit, x61 y134 w70 h20 vFarm2, Edit
Gui, Add, Edit, x221 y84 w80 h20 vFarm3, 807`, 341
Gui, Add, Edit, x221 y134 w80 h20 vFarm4, Edit
Gui, Add, Text, x151 y84 w70 h20 , Farm 3
Gui, Add, Text, x151 y134 w70 h20 , Farm 4
Gui, Add, Text, x321 y84 w70 h20 , Text
Gui, Add, Edit, x391 y84 w80 h20 vFarm5, Edit
Gui, Add, Text, x321 y134 w70 h20 , Text
Gui, Add, Edit, x391 y134 w80 h20 vFarm6, Edit
Gui, Add, Text, x491 y84 w70 h20 , Text
Gui, Add, Edit, x581 y84 w80 h20 vFarm7, Edit
Gui, Add, Text, x491 y134 w70 h20 , Text
Gui, Add, Edit, x581 y134 w80 h20 vFarm8, Edit
Gui, Show, x321 y200 h257 w745, GrepoFarm ~~~~~ Hockeyman271 ~~~~~~
return
GuiClose:
ExitApp
return
Ok: ; label triggered by the button
Gui, submit, nohide ; hide or nohide depends on what you want
FileCreateDir, %A_WorkingDir%\Data\%City%
if ErrorLevel
MsgBox ERROR Creating Directory for "%City%"
FileAppend, %City%, %A_WorkingDir%\Data\%City%\city.txt
FileAppend, %Farm1%, %A_WorkingDir%\Data\%City%\farm1.txt
FileAppend, %Farm2%, %A_WorkingDir%\Data\%City%\farm2.txt
FileAppend, %Farm3%, %A_WorkingDir%\Data\%City%\farm3.txt
FileAppend, %Farm4%, %A_WorkingDir%\Data\%City%\farm4.txt
FileAppend, %Farm5%, %A_WorkingDir%\Data\%City%\farm5.txt
FileAppend, %Farm6%, %A_WorkingDir%\Data\%City%\farm6.txt
FileAppend, %Farm7%, %A_WorkingDir%\Data\%City%\farm7.txt
FileAppend, %Farm8%, %A_WorkingDir%\Data\%City%\farm8.txt
Gui, Destroy
return
}
Upvotes: 0
Views: 1122
Reputation: 6370
Ah, from what it looks like, you are doing a few things wrong.
And, if I am not mistaken, you may be only creating ONE GUI! The loop runs, and all the controls get added to the same GUI. If you add a gui, show
you will see that.
Also, don't put your return in the loop or the loop will stop - which will explain why your loop quit after one GUI was created.
Try something like this:
n = 1
Loop:
{
gosub, BuildNewForm
n++
}
BuildNewForm:
Gui, GrepoFarm%n%:new ;name the gui with it's number to keep the GUI's different
Gui, Add, Button, x1 y174 w110 h40 gOK, Button
Gui, Show, x321 y200 h257 w745, GrepoFarm ~~~~~ Hockeyman271 ~~~~~~
return
GuiClose:
ExitApp
return
;other subs and functions
Upvotes: 1