Get content of GUI edit controls using loop
Posted: 25 Nov 2018, 16:32
Hi all,
I have a GUI with four Edit controls where the user can input data, and a subroutine that checks the contents of every Edit control; if empty, don't do anything, if not empty, append the contents of the edit control and the related text element to clipboard.
For the sake of learning something new and writing more flexible code I would like to do this with a loop instead. Loop four times, using a_index to check each edit one after the other. However: I can't figure out a way to use a_index to identify the vlabel I need.
The code below does what I need it to but relies on four separate if-checks. This is the part I would like to automate using a loop.
Thanks in advance for any help!
I have a GUI with four Edit controls where the user can input data, and a subroutine that checks the contents of every Edit control; if empty, don't do anything, if not empty, append the contents of the edit control and the related text element to clipboard.
For the sake of learning something new and writing more flexible code I would like to do this with a loop instead. Loop four times, using a_index to check each edit one after the other. However: I can't figure out a way to use a_index to identify the vlabel I need.
The code below does what I need it to but relies on four separate if-checks. This is the part I would like to automate using a loop.
Code: Select all
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
gui,assistant:new,resize
gui,add,text,vCID_L,Customer ID
gui,add,text,x156 yp vPID_L,Partner ID
gui,add,edit,xs w108 r1 vCID
gui,add,edit,x156 yp w108 r1 vPID
gui,add,text,xs vORDID_L,Order ID
gui,add,text,x156 yp vCONID_L,Contract ID
gui,add,edit,xs w108 r1 vORDID
gui,add,edit,x156 yp w108 r1 vCONID
gui,add,button,xs w85 r2 gCopy,Copy all
gui,show,,Assistant
return
Copy:
gui,assistant:submit
clipboard := "NOTES"
if(CID != "")
{
guicontrolget,CID_L
clipboard .= "`r`n" CID_L ": " CID
}
if(PID != "")
{
guicontrolget,PID_L
clipboard .= "`r`n" PID_L ": " PID
}
if(ORDID != "")
{
guicontrolget,ORDID_L
clipboard .= "`r`n" ORDID_L ": " ORDID
}
if(CONID != "")
{
guicontrolget,CONID_L
clipboard .= "`r`n" CONID_L ": " CONID
}
msgbox, % clipboard
return
GuiClose:
ExitApp