Siimple timer works, but output is not in format I wanted

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DanRim
Posts: 153
Joined: 20 Jul 2018, 15:16

Siimple timer works, but output is not in format I wanted

26 Sep 2021, 10:37

Hello everyone,

Hope you having good weekend. Some chilling and some coding :) Maybe some one could help met to find what I missing and do not see, because I do not understand why I do not get wanted time format.

To speed just change → Settimer, Stopwatch, 1000 to 100.
I want to display always format 02:01:15, but for some reason I do not understand why I get always 2:1:15, and then seconds get to max point, its reseting to 000?

Code: Select all


#SingleInstance, Force
;Source: https://autohotkey.com/board/topic/88714-simple-stop-watch/
timerh := "00"
timerm := "00"
timers := "00"
stopped := "0"

Gui, Add, Button, x2 y42 w80 h20 vPause, Pause
Gui, Add, Button, x82 y42 w80 h20 vReset, Reset
Gui, Add, Text, x67 y22 w60 h20 BackgroundTrans E0x20 vTText, %timerh%:%timerm%:%timers%
Gui, Show, h69 w165, Stopwatch
Settimer, Stopwatch, 1000
Return

Stopwatch:
timers += 1
if(timers > 59)  ; 59
{
	timerm += 1
	timers := "00"
	GuiControl, , TText ,   %timerh%:%timerm%:%timers%
}
if(timerm > 59) ;59
{
    timerh += 1
	timerm := "00"
	timers := "00"
	GuiControl, , TText ,   %timerh%:%timerm%:%timers%
}
if(timers < 10)
{
	GuiControl, , TText ,   %timerh%:%timerm%:0%timers%
}
else
{
	GuiControl, , TText ,  %timerh%:%timerm%:%timers%
}
return

ButtonPause:
if(stopped = 0)
{
	Settimer, Stopwatch, off
	stopped = 1
}
else
{
	Settimer, Stopwatch, 999
	stopped = 0
}
return

ButtonReset:
timerh := "00"
timerm := "00"
timers := "00"
GuiControl, , TText ,   %timerh%:%timerm%:%timers%
return

GuiClose:
GuiEscape:
ExitApp



^!x::
TrayTip, %A_ScriptName% is closed, `n, 5, 17 ; `n makes empty, 5 means 5 sec, 17 type of icon 18 19 20 
/*
SetTimer, HideTrayTip, -2000

HideTrayTip() {
    TrayTip
}
*/

ExitApp



Attachments
format3.JPG
format3.JPG (4.41 KiB) Viewed 282 times
format2.JPG
format2.JPG (4.56 KiB) Viewed 282 times
format1.JPG
format1.JPG (5.08 KiB) Viewed 282 times
User avatar
mikeyww
Posts: 26869
Joined: 09 Sep 2014, 18:38

Re: Siimple timer works, but output is not in format I wanted

26 Sep 2021, 10:46

Format can help you format your numbers.

It seems to me that using a frequency of 999 ms will lead to inaccurate times.

Code: Select all

Try Menu, Tray, Icon, %A_WinDir%\System32\miguiresource.dll, 2
Gui, Font, s10
Gui, Add, Text  ,     w225 vTText  E0x20 Center
Gui, Add, Button,     w110 vPause, Pa&use
Gui, Add, Button, x+m wp         , &Reset
Gosub, ButtonReset                     ; Reset the timer
Gui, Show,, Stopwatch
Gosub, Start                           ; Start the timer

^!x::                                  ; Exit
GuiClose:
GuiEscape:
Gui, Hide
TrayTip, %A_ScriptName% is closing., `n,, 17
SoundBeep, 800
Sleep, 2000
TrayTip                                ; Hide the tray tip
If SubStr(A_OSVersion, 1 ,3) = "10." { ; For Windows 10
 Menu, Tray, NoIcon
 Sleep, 200
 Menu, Tray, Icon
}
ExitApp

Stopwatch:                             ; Timed routine to advance the stopwatch time
If (++timers > 59)
 timerm += 1, timers := "00"
If (timerm > 59)
 timerh += 1, timerm := "00"
Gosub, Update
Return

ButtonPause:                           ; Pause or resume
GuiControlGet, stopped,, Pause
If (stopped = "Pa&use") {              ; User clicked "Pause"
 SetTimer, Stopwatch, Off
 GuiControl,, Pause, Res&ume           ; Button: Pause -> Resume
 Gui, Color, FFFDCD ; Yellow
 SoundBeep, 1000
 Return
} Else GuiControl,, Pause, Pa&use      ; Button: Resume -> Pause
Start:                                 ; Start the timer
SetTimer, Stopwatch, 1000
Gui, Color, E7FFEB ; Green
SoundBeep, 1500
Return

ButtonReset:                           ; Reset the timer
timerh := timerm := timers := "00"
SoundBeep, 1900
Update:                                ; Update the display
GuiControl,, TText, % Format("{:02}:{:02}:{:02}", timerh, timerm, timers)
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Joey5 and 175 guests