GuiControl doesn't update variable on the GUI Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
boozlepuzzle
Posts: 10
Joined: 17 Feb 2021, 16:39

GuiControl doesn't update variable on the GUI

10 Apr 2021, 20:47

Code: Select all

 InputBox, input, Shutdown computer in.. (minutes)
shuttime:= (input * 60) * 1000 ;;Convert to miliseconds
Seconds:= input * 60
Gui, +AlwaysOnTop
Gui, Add, Text,, Computer shutting down in
Gui, Add, Text,, Seconds
Gui, Add, Text,, seconds
Gui, Show, NoActivate, System
Loop {
	sleep 1000
	Seconds:= Seconds -1
	GuiControl,, Seconds, %Seconds%
	if(seconds  = 0)
		break
		}
shutdown, 5
return
Hey guys, as you might have guessed I'm trying to make a simple shutdown timer, with a GUI to display how many seconds are left until shutdown, the loop works perfectly fine, I chose one minute and it took exactly one minute to shut down, the problem is that the GuiControl command fails to update the Seconds variable in the GUI, it only works once at first and then it gets stuck on 59 the rest of the time, am I doing something wrong? thanks a lot for always helping
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: GuiControl doesn't update variable on the GUI  Topic is solved

10 Apr 2021, 20:58

You have to use the v option when you add the control to link a variable to it:

Code: Select all

InputBox, input, Shutdown computer in.. (minutes)
shuttime:= (input * 60) * 1000 ;;Convert to miliseconds
Seconds:= input * 60
Gui, +AlwaysOnTop
Gui, Add, Text,, Computer shutting down in
Gui, Add, Text, vSecondsTxt w100
Gui, Add, Text,, seconds
Gui, Show, NoActivate, System
Loop {
	sleep 1000
	Seconds:= Seconds -1
	GuiControl,, SecondsTxt, %Seconds%
	if(seconds  = 0)
		break
		}
msgbox shutdown
return
boozlepuzzle
Posts: 10
Joined: 17 Feb 2021, 16:39

Re: GuiControl doesn't update variable on the GUI

10 Apr 2021, 21:13

boiler wrote:
10 Apr 2021, 20:58
You have to use the v option when you add the control to link a variable to it:

Code: Select all

InputBox, input, Shutdown computer in.. (minutes)
shuttime:= (input * 60) * 1000 ;;Convert to miliseconds
Seconds:= input * 60
Gui, +AlwaysOnTop
Gui, Add, Text,, Computer shutting down in
Gui, Add, Text, vSecondsTxt w100
Gui, Add, Text,, seconds
Gui, Show, NoActivate, System
Loop {
	sleep 1000
	Seconds:= Seconds -1
	GuiControl,, SecondsTxt, %Seconds%
	if(seconds  = 0)
		break
		}
msgbox shutdown
return
Thank you so much! I had no idea about those

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: wpulford and 397 guests