1
votes

I am trying to automate the process of generating a template to request medical exams from our outsourced provider. There are six GUIs in the script:

  • Special Instructions
  • List Upcoming Appointments
  • Contact Information
  • Power of Attorney Listed?
  • Electronic or Hard-Copy File?
  • Authorization Number and Effective Date Range

Each GUI asks the user to pick one choice or the other, and based on the answers, pastes a block of text in the template.

The first GUI for special instructions runs just fine. But instead of proceeding to the second GUI, the script ends. I used the SciTE4 editor to try to see what's going on, and after the first GUI runs, it skips to the very end.

Here's the code for the first two GUIs and the end:

;SPECIAL INSTRUCTIONS GUI
;Gui, Add, Text, W400 H40, Special instructions?
Gui, Add, Radio, vSpecInstrs Checked, Yes
Gui, Add, Radio, , No
Gui, Add, Edit, W370 r4 vListofInstrs, 
Gui, Add, Button, vButtonNext1 gNextSelected1, Next
Gui, Add, Button, xp+60 vButtonCancel1 gCancelSelected1, Cancel
Gui, Show, W400 H150, Special Instructions?
return
;

NextSelected1:
Gui, Submit, ; Save the input from the user to each control's associated variable.
If SpecInstrs = 1 
{
  SendInput >{space 2}>{space 2}>{space 2}>{space 2}>{space 2}IMPORTANT{!}{space 2}<{space 2}<{space 2}<{space 2}<{space 2}<
  Send {Enter 2}
  SendInput %ListofInstrs%
  Send {Enter 2}
  }
Else If SpecInstrs = 2
  {
  Send {Enter 2}
  }
SpecInstrs = 0
FileType = 
Gui, Destroy
;Return
;
; Actions on Cancel or Close
;
CancelSelected1:
;GuiClose:
;ExitApp
gosub, GuiClose
;Return

;UPCOMING APPOINTMENTS GUI
Gui, Add, Text, Center W200 H50, UPCOMING APPOINTMENTS?
Gui, Add, Radio, vAppts checked, Yes
Gui, Add, Radio, , No
Gui, Add, Button, vButtonNext2 gNextSelected2, Next
Gui, Add, Button, xp+60 vButtonCancel2 gCancelSelected2, Cancel
Gui, Show, , Appointments
return
;

NextSelected2:
Gui, Submit, ; Save the input from the user to each control's associated variable.
If Appts = 1
  {
  SendInput >{space 2}>{space 2}>{space 2}>{space 2}>{space 2}Future  Appointments - Do NOT Schedule On This Date{(}s{)}{space}<{space 2}<{space 2}<{space 2}<{space 2}<
  Send {Enter 2}
  SendInput {[}Copy and paste appointments from CPRS here{]} 
  Send {Enter 2}
  SendInput >{space 2}>{space 2}>{space 2}>{space 2}>{space 2}<{space 2}<{space 2}<{space 2}<{space 2}<
  Send {Enter 2}    
  }
Else If Appts = 2
  {
  Send Appointments pending:  None 
  Send {Enter 2}
  }
Gui, Destroy
Appts = 0  
Return
;
; Actions on Cancel or Close
;
CancelSelected2:
gosub, GuiClose
;GuiClose:
;ExitApp
Return

The code actually never gets to the Upcoming Appointments GUI. In running the debugger, after I select the Next button, it skips to the very end code:

;
;
GuiClose:
  ExitApp
Return

I'd paste the rest of the code, but I figure if I can figure out how to make GUI 2 run after GUI 1, I can make the others work. (Besides, if I can't even get GUI 2 to run, who cares about the rest?!). I appreciate any help!

1
The return after NextSelected1 (before CancelSelected1) is missing / commented out, meaning that when you press ButtonNext1, gosub, GuiClose will also be executed - phil294
Unfortunately, that didn't help. I removed the semi-colon from the Return in the NextSelected1 section, but only that first section executes, whether I check Yes (pastes in the first part of the template) or No (two Enter/CRs to leave room for the next step). - JBM
please consider updating the question startpost, so we can actually reproduce your problem. Also, the code has been outdate before already - in your code, there is no such label as GuiClose, just commented out three times - phil294
I just left those GuiClose things in "just in case" those were not the problem as I had once thought. It probably would have made it neater to simply delete them. - JBM

1 Answers

1
votes

There seems to be a major misunderstanding about the return keyword for you: AutoHotkey starts executing the top of the script until the first return occurs. After that, only hotkeys, hotstrings, functions and, most importantly for you, labels may follow.

Some random AutoHotkey script might look like the following:

#noEnv
sendMode, Input
setWorkingDir, %A_WorkingDir%
Gui, 1:add, button, gbuttonpressed, press me
Gui, 1:show
return

; any random commands here will never be executed, if not enclose in a labe, hotkey etc!

buttonpressed:
gui, 1:destroy
msgbox, hi!
goSub, secondGui_start
return

secondGui_start:
Gui, 2:add, text,, this Gui will show after the first one
Gui, 2:show
return

2GuiClose:
exitApp
return

back to your script.

When pressing the button with the associated variable ButtonNext, the label NextSelected1 is being called. It ends with

Gui, Destroy
Return

, but you expect someting to happen afterwards! So tell the compiler you want to move on to the next Gui before return. Otherwise, the script becomes idle, and since you don't have neither hotkeys nor hotstrings nor the #persistent keyword attached, the script terminates.

Do so using the GoTo keyword. If you put your second gui in its own label, you can call this way then.

Finally, if you want to manage multiple guis, then number them, as I did in the example above.