Download PDF version - ComputorEdge
Transcript
The Variable Already Exists
ComputorEdge
window is loaded only once when it first runs by locating the GUI code in the auto-execute
area at the beginning of the script. Then, whenever the window needs to display, a hotkey
subroutine which includes only the Gui, Show command is used. That way the script never
attempts to create the same variables again.
Another option is to include the Gui, Destroy command in the subroutine that closes the
window. This will clear the GUI controls and all of their variables from memory, thus allowing
the recreation of the GUI and all variables the next time it's needed. However, any settings
changed or set to non-default values will be lost (reset to the defaults).
Another way to avoid the error without destroying the GUI even though the GUI setup code
exists within the same hotkey routine is to only run the GUI setup when it does not exist. The
following is an example of this approach which prevents the error while allowing the GUI to
maintain the last date set:
^#D::
DetectHiddenWindows, On
IfWinNotExist, Select Date
{
Gui AddDate:Add, MonthCal, vDayPick
Gui AddDate:Add, Button, Default, Submit
}
Gui AddDate:Show,, Select Date
DetectHiddenWindows, Off
Return
AddDateButtonSubmit:
Gui AddDate:Submit
FormatTime, DayPick, %DayPick%, MMMM d, yyyy
Send, %DayPick%
Return
This is an AutoHotkey script which uses the MonthCal control to select and add a formatted
date to any document (i.e. May 28, 2013) (see Figure 5). This is a modification of the
AddDate.ahk script found on the download site, but altered to be included in a larger group of
AutoHotkey apps combined into one script.
23