text not updating from settimer Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
amitavak
Posts: 3
Joined: 08 Feb 2017, 09:19

text not updating from settimer

24 Feb 2017, 02:36

I am trying to change text from set timer. It is not working. Here is the pseudo code what I am trying to do

Code: Select all

Gui, New, , Update Text Demo
gui, add, text, x20 y20 w100 h16 vtimertext, --------
Gui, show, w600 h300

TimePassed = 0

SetTimer, UpdateTime, 3000
gosub UpdateTime

Return

; The following label receives control when the user closes the GUI window.
GuiClose:
{
  ExitApp
}

Return

UpdateTime:
{
  TimePassed := (TimePassed + 1)
  TrayTip, Debug, %TimePassed%
  GuiControl,,timertext,%TimePassed%
}

Return
As you can see, timer text is not changing when it is called from the settimer event.

Could someone please point out if I am doing something wrong.

Thanks.
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
Contact:

Re: text not updating from settimer  Topic is solved

24 Feb 2017, 03:01

amitavak wrote:As you can see, timer text is not changing when it is called from the settimer event.
Could someone please point out if I am doing something wrong.
Thanks.
Well, GuiControl,, TimerText wasn't found because it wasn't a global variable.
To avoid global you need to specify the gui name. ( it was also missing the Text command )
Hope you don't mind, I changed a few things like removing your TimePassed variable

Code: Select all

#singleinstance force

Gui MyGui:New, , % "Update Text Demo"
Gui MyGui:Add, Text, x20 y20 w100 h16 vTimerText, % "0"
Gui MyGui:Show, w600 h300

SetTimer UpdateTime, 3000

Return
GuiClose:
ExitApp

UpdateTime:
	GuiControlGet TimerText
	TimerText++
	TrayTip Debug, % TimerText
	GuiControl MyGui:Text, TimerText, % TimerText
Return
amitavak
Posts: 3
Joined: 08 Feb 2017, 09:19

Re: text not updating from settimer

24 Feb 2017, 03:56

Thank you 4GForce. It was a great help.
I am newbie to ahk. I appreciate that you pointed out the mistakes. Thanks again.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], peter_ahk, petery and 200 guests