Variable assosiated to contol updating without Submiting? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
truekefir
Posts: 17
Joined: 29 Jul 2017, 13:57

Variable assosiated to contol updating without Submiting?

11 Aug 2017, 07:00

So I read in mannual
"For example, specifying vMyEdit would store the control's contents in the variable MyEdit whenever the Gui Submit command is used."

I'm not using GuiSubmit but once I change the date in the DateTime control it updated %CustomDate%, why is that?

Code: Select all

#SingleInstance force
#NoEnv ; no idea what it does
CustomDate := ""
GuiWidth := 180


Gui +LastFound +AlwaysOnTop 
Gui, Add, DateTime, vCustomDate w120 r1 ChooseNone, yyyy-MM-dd
Gui, Add, Button, gSET x+4 , SET
Gui, Add, Text, % "x7 y+1 w" (GuiWidth-14) " h0 vP"
GuiControlGet, P, Pos
H := PY + PH
Gui, Show, % "w" GuiWidth " NA x500", TestUI



Loop
	{
	Sleep, 5000
	MsgBox, %CustomDate%
	}

Set:
	GuiControlGet, CustomDate
	if (CustomDate != "")
		FormatTime, CustomDate, %CustomDate%, yyyy-MM-dd
return

GuiClose:
	ExitApp
User avatar
Gio
Posts: 1247
Joined: 30 Sep 2013, 10:54
Location: Brazil

Re: Variable assosiated to contol updating without Submiting?  Topic is solved

11 Aug 2017, 11:28

Hello Truekefir.

Welcome to the AutoHotkey community forums.
If the control has a g-label, the label is launched whenever the user changes the date or time. For each launch, the control's associated output variable (if any) is automatically updated with the currently selected date/time.


The quote above from the docs seems to imply that automatic submit (sentence 2) occurs "if the control has a g-label" (sentence 1), but it does seem to work regardless of the control even having a g-label at all. I am not sure if this was intended by the programmer, but if this behavior is undesired you can use GuiControlGet with a variable that is NOT the same as the controls variable. Example below.

Code: Select all

#SingleInstance force
#NoEnv ; no idea what it does
CustomDate := ""
GuiWidth := 180


Gui +LastFound +AlwaysOnTop 
Gui, Add, DateTime, w120 r1, yyyy-MM-dd ; ---- VARIABLE REMOVED FROM THIS LINE ----
Gui, Add, Button, gSET x+4 , SET
Gui, Add, Text, % "x7 y+1 w" (GuiWidth-14) " h0 vP"
GuiControlGet, P, Pos
H := PY + PH
Gui, Show, % "w" GuiWidth " NA x500", TestUI



Loop
	{
	Sleep, 5000
	MsgBox, %CustomDate%
	}
	
Return
Set:
	GuiControlGet, CustomDate,, SysDateTimePick321
	if (CustomDate != "")
		FormatTime, CustomDate, %CustomDate%, yyyy-MM-dd
return

GuiClose:
	ExitApp
SysDateTimePick321 refers to the first DateTime control of a window. Use SysDateTimePick322 and so on for other DateTime controls in the same window.

Best wishes.
truekefir
Posts: 17
Joined: 29 Jul 2017, 13:57

Re: Variable assosiated to contol updating without Submiting?

11 Aug 2017, 13:51

Gio wrote:but if this behavior is undesired you can use GuiControlGet with a variable that is NOT the same as the controls variable.
I've figured couple of ways to work around to achieve the goal but I needed to know if I wasn't doing it wrong at the start :) Your way looks way more elegant though, thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, nqminh90 and 151 guests