Jump to content

Timer


akcza
 Share

Recommended Posts

Hi, I would need a help. I don't know how to do it to be able to run multiple clocks in one script. I based od script from this https://www.autoitscript.com/forum/topic/161337-simple-stopwatch-udf/?tab=comments#comment-1171171 and "Time2" work but the rest isnt working. Could you help me?


 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region
Global $Name = GUICreate("AutoIt", 690, 176, 263, 271)
GUICtrlCreatePic('background.jpg', 0, 0, 0, 0)
GUICtrlSetState(-1, $GUI_DISABLE)

Global $Work = GUICtrlCreateLabel("Time1", 56, 24, 55, 32)
GUICtrlSetFont(-1, 15, 800, 0, "Segoe UI")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1,  $GUI_BKCOLOR_TRANSPARENT)
$Time = GUICtrlCreateLabel("   00:00:00.0", 25, 60, 200, 25)
GUICtrlSetFont(-1, 14)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1,  $GUI_BKCOLOR_TRANSPARENT)
$Button1 = GUICtrlCreateButton("Start/Stop", 20, 90, 60, 25)
$Button2 = GUICtrlCreateButton("Restart", 80, 90, 60, 25)


Global $Idle = GUICtrlCreateLabel("Time2", 208, 24, 39, 32)
GUICtrlSetFont(-1, 15, 800, 0, "Segoe UI")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1,  $GUI_BKCOLOR_TRANSPARENT)
$Time1 = GUICtrlCreateLabel("   00:00:00.0", 170, 60, 200, 25)
GUICtrlSetFont(-1, 14)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1,  $GUI_BKCOLOR_TRANSPARENT)
$Button3 = GUICtrlCreateButton("Start/Stop", 170, 90, 60, 25)
$Button4 = GUICtrlCreateButton("Restart", 230, 90, 60, 25)

Global $Meeting = GUICtrlCreateLabel("Time3", 560, 24, 83, 32)
GUICtrlSetFont(-1, 15, 800, 0, "Segoe UI")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1,  $GUI_BKCOLOR_TRANSPARENT)
$Time2 = GUICtrlCreateLabel("   00:00:00.0", 350, 60, 200, 25)
GUICtrlSetFont(-1, 14)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1,  $GUI_BKCOLOR_TRANSPARENT)
$Button5 = GUICtrlCreateButton("Start/Stop", 350, 90, 60, 25)
$Button6 = GUICtrlCreateButton("Restart", 410, 90, 60, 25)

Global $Education = GUICtrlCreateLabel("Time4", 360, 24, 98, 32)
GUICtrlSetFont(-1, 15, 800, 0, "Segoe UI")
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1,  $GUI_BKCOLOR_TRANSPARENT)
$Time3 = GUICtrlCreateLabel("   00:00:00.0", 540, 60, 200, 25)
GUICtrlSetFont(-1, 14)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1,  $GUI_BKCOLOR_TRANSPARENT)
$Button7 = GUICtrlCreateButton("Start/Stop", 540, 90, 60, 25)
$Button8 = GUICtrlCreateButton("Restart", 600, 90, 60, 25)
GUISetState(@SW_SHOW)
#EndRegion


Stopwatch1(2) ; reset to 0 and stops
While 2
    $x1 = Int(Stopwatch1() / 100)
    $nMsg1 = GUIGetMsg()
    Switch $nMsg1
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button3 ; toggle status (go <-> pause)
            Stopwatch1() ; this reads counter and sets @extended according to actual $paused status
            Stopwatch1(@extended) ;    if is paused (@extended = 1) then unpause [Stopwatch(1)]
            ;                         if is unpaused (@extended = 0) then pause [Stopwatch(0)]
        Case $Button4 ; reset to 0 and restart counter
            Stopwatch1(3)
    EndSwitch

    If $x1 <> Int(Stopwatch1() / 100) Then
        $totsec1 = Int(Stopwatch1() / 1000) ; ms to sec
        $hr1 = Int($totsec1 / 3600) ; hours
        $mn1 = Int(($totsec1 - ($hr1 * 3600)) / 60) ; minutes
        $sc1 = Int(($totsec1 - ($hr1 * 3600) - ($mn1 * 60))) ; seconds
        $tn1 = Int((Int(Stopwatch1() / 100) - ($hr1 * 36000) - ($mn1 * 600) - ($sc1 * 10))) ; tenths of a second
        GUICtrlSetData($Time1, "   " & StringFormat("%02s", $hr1) & ":" & StringFormat("%02s", $mn1) & ":" & StringFormat("%02s", $sc1) & "." & StringFormat("%01s", $tn1))
    EndIf
WEnd
; --- end of example ---

Func Stopwatch1($ToggleTo = 4)
    Static Local $Paused1 = True
    Static Local $Stopwatch1 = 0
    Static Local $TotalTime1 = 0
    Switch $ToggleTo
        Case 0 ; pause counter
            If $Paused1 Then
                SetExtended($Paused1) ; $Paused status
                Return $TotalTime1 ; already paused, just return current $TotalTime
            Else
                $TotalTime1 += TimerDiff($Stopwatch1)
                $Paused1 = True
                SetExtended($Paused1)
                Return $TotalTime1
            EndIf
        Case 1 ; unpause counter
            If $Paused1 Then
                $Stopwatch1 = TimerInit()
                $Paused1 = False
                SetExtended($Paused1)
                Return $TotalTime1
            Else
                SetExtended($Paused1)
                Return $TotalTime1 + TimerDiff($Stopwatch1)
            EndIf
        Case 2 ; reset to 0 and pause
            $Paused1 = True
            $TotalTime1 = 0
            SetExtended($Paused1)
            Return $TotalTime1
        Case 3 ; reset to 0 and restart
            $Paused1 = False
            $TotalTime1 = 0
            $Stopwatch1 = TimerInit()
            SetExtended($Paused1)
            Return $TotalTime1
        Case 4 ; return status
            SetExtended($Paused1)
            If $Paused1 Then
                Return $TotalTime1
            Else
                Return $TotalTime1 + TimerDiff($Stopwatch1)
            EndIf
    EndSwitch
EndFunc   ;==>Stopwatch1

Stopwatch(2) ; reset to 0 and stops
While 1
    $x = Int(Stopwatch() / 100)
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ; toggle status (go <-> pause)
            Stopwatch() ; this reads counter and sets @extended according to actual $paused status
            Stopwatch(@extended) ;    if is paused (@extended = 1) then unpause [Stopwatch(1)]
            ;                         if is unpaused (@extended = 0) then pause [Stopwatch(0)]
        Case $Button2 ; reset to 0 and restart counter
            Stopwatch(3)
    EndSwitch

    If $x <> Int(Stopwatch() / 100) Then
        $totsec = Int(Stopwatch() / 1000) ; ms to sec
        $hr = Int($totsec / 3600) ; hours
        $mn = Int(($totsec - ($hr * 3600)) / 60) ; minutes
        $sc = Int(($totsec - ($hr * 3600) - ($mn * 60))) ; seconds
        $tn = Int((Int(Stopwatch() / 100) - ($hr * 36000) - ($mn * 600) - ($sc * 10))) ; tenths of a second
        GUICtrlSetData($Time, "   " & StringFormat("%02s", $hr) & ":" & StringFormat("%02s", $mn) & ":" & StringFormat("%02s", $sc) & "." & StringFormat("%01s", $tn))
    EndIf
WEnd
; --- end of example ---

Func Stopwatch($ToggleTo = 4)
    Static Local $Paused = True
    Static Local $Stopwatch = 0
    Static Local $TotalTime = 0
    Switch $ToggleTo
        Case 0 ; pause counter
            If $Paused Then
                SetExtended($Paused) ; $Paused status
                Return $TotalTime ; already paused, just return current $TotalTime
            Else
                $TotalTime += TimerDiff($Stopwatch)
                $Paused = True
                SetExtended($Paused)
                Return $TotalTime
            EndIf
        Case 1 ; unpause counter
            If $Paused Then
                $Stopwatch = TimerInit()
                $Paused = False
                SetExtended($Paused)
                Return $TotalTime
            Else
                SetExtended($Paused)
                Return $TotalTime + TimerDiff($Stopwatch)
            EndIf
        Case 2 ; reset to 0 and pause
            $Paused = True
            $TotalTime = 0
            SetExtended($Paused)
            Return $TotalTime
        Case 3 ; reset to 0 and restart
            $Paused = False
            $TotalTime = 0
            $Stopwatch = TimerInit()
            SetExtended($Paused)
            Return $TotalTime
        Case 4 ; return status
            SetExtended($Paused)
            If $Paused Then
                Return $TotalTime
            Else
                Return $TotalTime + TimerDiff($Stopwatch)
            EndIf
    EndSwitch
EndFunc   ;==>Stopwatch

 

Link to comment
Share on other sites

On 8/23/2022 at 5:56 PM, akcza said:

Hi, I would need a help. I don't know how to do it to be able to run multiple clocks in one script. I based od script from this https://www.autoitscript.com/forum/topic/161337-simple-stopwatch-udf/?tab=comments#comment-1171171 and "Time2" work but the rest isnt working. Could you help me?

Hi @akcza

That function was a single StopWatch experiment. But you gave me an idea to implement the possibility of creating multiple StopWatches with the same function (just a little bit modified but still compatible with the original version).

To create additional stopwatches in addition to the first one, call the function with option 5, and you will receive an index to use as the second parameter for subsequent queries relating to the new stopwatch just created.

I have edited your script (and the original stopwatch() function as well) to give an idea of what I mean. The script as it is is a bit verbose and could be tweaked, but I think it gives the idea

hope I was helpful

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region
Global $Name = GUICreate("AutoIt", 690, 176, 263, 271)
GUICtrlCreatePic('background.jpg', 0, 0, 0, 0)
GUICtrlSetState(-1, $GUI_DISABLE)

Global $iFgColor = 0xFF0000

Global $Work = GUICtrlCreateLabel("Time1", 56, 24, 55, 32)
GUICtrlSetFont(-1, 15, 800, 0, "Segoe UI")
GUICtrlSetColor(-1, $iFgColor)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Time = GUICtrlCreateLabel("   00:00:00.0", 25, 60, 200, 25)
GUICtrlSetFont(-1, 14)
GUICtrlSetColor(-1, $iFgColor)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Button1 = GUICtrlCreateButton("Start/Stop", 20, 90, 60, 25)
$Button2 = GUICtrlCreateButton("Restart", 80, 90, 60, 25)

Global $Work_Stpowatch = 0 ; Default stopwatch


Global $Idle = GUICtrlCreateLabel("Time2", 208, 24, 39, 32)
GUICtrlSetFont(-1, 15, 800, 0, "Segoe UI")
GUICtrlSetColor(-1, $iFgColor)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Time1 = GUICtrlCreateLabel("   00:00:00.0", 170, 60, 200, 25)
GUICtrlSetFont(-1, 14)
GUICtrlSetColor(-1, $iFgColor)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Button3 = GUICtrlCreateButton("Start/Stop", 170, 90, 60, 25)
$Button4 = GUICtrlCreateButton("Restart", 230, 90, 60, 25)

Global $Idle_Stopwatch = Stopwatch(5) ; option 5 -> create a new stopwatch

Global $Meeting = GUICtrlCreateLabel("Time3", 560, 24, 83, 32)
GUICtrlSetFont(-1, 15, 800, 0, "Segoe UI")
GUICtrlSetColor(-1, $iFgColor)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Time2 = GUICtrlCreateLabel("   00:00:00.0", 350, 60, 200, 25)
GUICtrlSetFont(-1, 14)
GUICtrlSetColor(-1, $iFgColor)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Button5 = GUICtrlCreateButton("Start/Stop", 350, 90, 60, 25)
$Button6 = GUICtrlCreateButton("Restart", 410, 90, 60, 25)

Global $Meeting_Stopwatch = Stopwatch(5) ; option 5 -> create a new stopwatch

Global $Education = GUICtrlCreateLabel("Time4", 360, 24, 98, 32)
GUICtrlSetFont(-1, 15, 800, 0, "Segoe UI")
GUICtrlSetColor(-1, $iFgColor)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Time3 = GUICtrlCreateLabel("   00:00:00.0", 540, 60, 200, 25)
GUICtrlSetFont(-1, 14)
GUICtrlSetColor(-1, $iFgColor)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$Button7 = GUICtrlCreateButton("Start/Stop", 540, 90, 60, 25)
$Button8 = GUICtrlCreateButton("Restart", 600, 90, 60, 25)

Global $Education_Stopwatch = Stopwatch(5) ; option 5 -> create a new stopwatch

GUISetState(@SW_SHOW)
#EndRegion


; initialize timeouts for refresh labels
$x1 = Int(Stopwatch(4, $Work_Stpowatch) / 100)
$x2 = Int(Stopwatch(4, $Idle_Stopwatch) / 100)
$x3 = Int(Stopwatch(4, $Meeting_Stopwatch) / 100)
$x4 = Int(Stopwatch(4, $Education_Stopwatch) / 100)

While 1

    $nMsg1 = GUIGetMsg()
    Switch $nMsg1
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ; toggle status (go <-> pause)
            Stopwatch(4, $Work_Stpowatch) ; this reads counter and sets @extended according to actual $paused status
            Stopwatch(@extended, $Work_Stpowatch) ;    if is paused (@extended = 1) then unpause [Stopwatch(1)]
            ;                         if is unpaused (@extended = 0) then pause [Stopwatch(0)]
        Case $Button2  ; reset to 0 and restart counter
            Stopwatch(3, $Work_Stpowatch)

            ; ----- repeat the above logic for the other buttons below as well

        Case $Button3
            Stopwatch(4, $Idle_Stopwatch)
            Stopwatch(@extended, $Idle_Stopwatch)
        Case $Button4
            Stopwatch(3, $Idle_Stopwatch)
            ; ----------
        Case $Button5
            Stopwatch(4, $Meeting_Stopwatch)
            Stopwatch(@extended, $Meeting_Stopwatch)

        Case $Button6
            Stopwatch(3, $Meeting_Stopwatch)
            ; ----------
        Case $Button7
            Stopwatch(4, $Education_Stopwatch)
            Stopwatch(@extended, $Education_Stopwatch)
        Case $Button8
            Stopwatch(3, $Education_Stopwatch)
    EndSwitch


    If $x1 <> Int(Stopwatch(4, $Work_Stpowatch) / 100) Then
        GUICtrlSetData($Time, "   " & _Time_Format(4, $Work_Stpowatch))
        $x1 = Int(Stopwatch(4, $Work_Stpowatch) / 100)
    EndIf

    If $x1 <> Int(Stopwatch(4, $Idle_Stopwatch) / 100) Then
        GUICtrlSetData($Time1, "   " & _Time_Format(4, $Idle_Stopwatch))
        $x1 = Int(Stopwatch(4, $Idle_Stopwatch) / 100)
    EndIf

    If $x1 <> Int(Stopwatch(4, $Meeting_Stopwatch) / 100) Then
        GUICtrlSetData($Time2, "   " & _Time_Format(4, $Meeting_Stopwatch))
        $x1 = Int(Stopwatch(4, $Meeting_Stopwatch) / 100)
    EndIf

    If $x1 <> Int(Stopwatch(4, $Education_Stopwatch) / 100) Then
        GUICtrlSetData($Time3, "   " & _Time_Format(4, $Education_Stopwatch))
        $x1 = Int(Stopwatch(4, $Education_Stopwatch) / 100)
    EndIf

WEnd

Func _Time_Format($QueryCode, $StopwatchIndex)

    Local $totsec1 = Int(Stopwatch($QueryCode, $StopwatchIndex) / 1000)         ; ms to sec
    Local $hr1 = Int($totsec1 / 3600)     ; hours
    Local $mn1 = Int(($totsec1 - ($hr1 * 3600)) / 60)     ; minutes
    Local $sc1 = Int(($totsec1 - ($hr1 * 3600) - ($mn1 * 60)))     ; seconds
    Local $tn1 = Int((Int(Stopwatch($QueryCode, $StopwatchIndex) / 100) - ($hr1 * 36000) - ($mn1 * 600) - ($sc1 * 10)))     ; tenths of a second

    Return StringFormat("%02s", $hr1) & ":" & StringFormat("%02s", $mn1) & ":" & StringFormat("%02s", $sc1) & "." & StringFormat("%01s", $tn1)

EndFunc   ;==>_Time_Format

; --- end of example ---

Func Stopwatch($ToggleTo = 4, $iDevice = 0)

    Static Local $Paused[1] = [True]
    Static Local $Stopwatch[1] = [0]
    Static Local $TotalTime[1] = [0]

    $iDevice = Int($iDevice)
    If $iDevice < 0 Or $iDevice > UBound($Stopwatch) - 1 Then Return SetError(1) ; error: requested data for an unexistent stopwatch

    Switch $ToggleTo
        Case 0 ; pause counter
            If $Paused[$iDevice] Then
                SetExtended($Paused[$iDevice]) ; $Paused status
                Return $TotalTime[$iDevice] ; already paused, just return current $TotalTime
            Else
                $TotalTime[$iDevice] += TimerDiff($Stopwatch[$iDevice])
                $Paused[$iDevice] = True
                SetExtended($Paused[$iDevice])
                Return $TotalTime[$iDevice]
            EndIf
        Case 1 ; unpause counter
            If $Paused[$iDevice] Then
                $Stopwatch[$iDevice] = TimerInit()
                $Paused[$iDevice] = False
                SetExtended($Paused[$iDevice])
                Return $TotalTime[$iDevice]
            Else
                SetExtended($Paused[$iDevice])
                Return $TotalTime[$iDevice] + TimerDiff($Stopwatch[$iDevice])
            EndIf
        Case 2 ; reset to 0 and pause
            $Paused[$iDevice] = True
            $TotalTime[$iDevice] = 0
            SetExtended($Paused[$iDevice])
            Return $TotalTime[$iDevice]
        Case 3 ; reset to 0 and restart
            $Paused[$iDevice] = False
            $TotalTime[$iDevice] = 0
            $Stopwatch[$iDevice] = TimerInit()
            SetExtended($Paused[$iDevice])
            Return $TotalTime[$iDevice]
        Case 4 ; return status
            SetExtended($Paused[$iDevice])
            If $Paused[$iDevice] Then
                Return $TotalTime[$iDevice]
            Else
                Return $TotalTime[$iDevice] + TimerDiff($Stopwatch[$iDevice])
            EndIf
        Case 5 ; Create an new stopwatch
            Local $iNewStopwatch = UBound($Paused) + 1

            ; create a new stopwacth
            ReDim $Paused[$iNewStopwatch]
            ReDim $Stopwatch[$iNewStopwatch]
            ReDim $TotalTime[$iNewStopwatch]

            ; initialize the new stopwatch
            $iNewStopwatch -= 1 ; adapt index for the array elements
            $Paused[$iNewStopwatch] = True
            $Stopwatch[$iNewStopwatch] = 0
            $TotalTime[$iNewStopwatch] = 0

            ; returns Index to point to this new stopwatch
            Return $iNewStopwatch
    EndSwitch
EndFunc   ;==>Stopwatch

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Here's my suggestion.

In the end it works the same as the solution by @Gianni, but in my opinion less flicker on the controls and better readability.

#include <GUIConstantsEx.au3>
#include "Timer.au3"

Opt("GuiOnEventMode", 1)

#Region Timer globals
Global $aiTimer[4] = [Null, Null, Null, Null]
Global $ahTimer[4] = [Null, Null, Null, Null]
Global $afTimer[4] = [0.0, 0.0, 0.0, 0.0]
#EndRegion Timer globals

#Region GUI
Global $iFgColor = 0xFF0000

Func _GUICtrlCreateLabel($text, $left, $top, $width, $height)
    Local $ctrlID = GUICtrlCreateLabel($text, $left, $top, $width, $height)
    GUICtrlSetFont($ctrlID, 15, 800, 0, "Segoe UI")
    GUICtrlSetColor($ctrlID, $iFgColor)
    GUICtrlSetBkColor($ctrlID, $GUI_BKCOLOR_TRANSPARENT)
    Return $ctrlID
EndFunc

Func _GUICtrlCreateLabel2($text, $left, $top, $width, $height)
    Local $ctrlID = GUICtrlCreateLabel($text, $left, $top, $width, $height)
    GUICtrlSetFont(-1, 14)
    GUICtrlSetColor($ctrlID, $iFgColor)
    GUICtrlSetBkColor($ctrlID, $GUI_BKCOLOR_TRANSPARENT)
    Return $ctrlID
EndFunc

Global $Name = GUICreate("AutoIt", 690, 176, 263, 271)
GUICtrlCreatePic('background.jpg', 0, 0, 0, 0)
GUICtrlSetState(-1, $GUI_DISABLE)

Global $Work = _GUICtrlCreateLabel("Time1", 56, 24, 55, 32)
$Time = _GUICtrlCreateLabel2("   00:00:00.0", 25, 60, 200, 25)
$Button1 = GUICtrlCreateButton("Start/Stop", 20, 90, 60, 25)
GUICtrlSetOnEvent(-1, "ToggleTimer1")
$Button2 = GUICtrlCreateButton("Restart", 80, 90, 60, 25)
GUICtrlSetOnEvent(-1, "ResetTimer1")


Global $Idle = _GUICtrlCreateLabel("Time2", 208, 24, 39, 32)
$Time1 = _GUICtrlCreateLabel2("   00:00:00.0", 170, 60, 200, 25)
$Button3 = GUICtrlCreateButton("Start/Stop", 170, 90, 60, 25)
GUICtrlSetOnEvent(-1, "ToggleTimer2")
$Button4 = GUICtrlCreateButton("Restart", 230, 90, 60, 25)
GUICtrlSetOnEvent(-1, "ResetTimer2")

Global $Meeting = _GUICtrlCreateLabel("Time3", 560, 24, 83, 32)
$Time2 = _GUICtrlCreateLabel2("   00:00:00.0", 350, 60, 200, 25)
$Button5 = GUICtrlCreateButton("Start/Stop", 350, 90, 60, 25)
GUICtrlSetOnEvent(-1, "ToggleTimer3")
$Button6 = GUICtrlCreateButton("Restart", 410, 90, 60, 25)
GUICtrlSetOnEvent(-1, "ResetTimer3")

Global $Education = _GUICtrlCreateLabel("Time4", 360, 24, 98, 32)
$Time3 = _GUICtrlCreateLabel2("   00:00:00.0", 540, 60, 200, 25)
$Button7 = GUICtrlCreateButton("Start/Stop", 540, 90, 60, 25)
GUICtrlSetOnEvent(-1, "ToggleTimer4")
$Button8 = GUICtrlCreateButton("Restart", 600, 90, 60, 25)
GUICtrlSetOnEvent(-1, "ResetTimer4")

GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "MyExit")
#EndRegion GUI

While 1
    Sleep(10)
WEnd

Func MyExit()
    Exit
EndFunc

Func Timer($ctrlID, $index)
    GUICtrlSetData($ctrlID, "   "&_Time_Format($afTimer[$index] + TimerDiff($ahTimer[$index])))
EndFunc

Func ToggleTimer($ctrlID, $index)
    If $ahTimer[$index] = Null Then
        $ahTimer[$index] = TimerInit()
        $aiTimer[$index] = setInterval("Timer", 100, $ctrlID, $index)
    Else
        $afTimer[$index] += TimerDiff($ahTimer[$index])
        clearInterval($aiTimer[$index])
        $ahTimer[$index] = Null
    EndIf
EndFunc

Func ResetTimer($index)
    $ahTimer[$index] = TimerInit()
    $afTimer[$index] = 0.0
EndFunc

Func ToggleTimer1()
    ToggleTimer($Time, 0)
EndFunc

Func ToggleTimer2()
    ToggleTimer($Time1, 1)
EndFunc

Func ToggleTimer3()
    ToggleTimer($Time2, 2)
EndFunc

Func ToggleTimer4()
    ToggleTimer($Time3, 3)
EndFunc

Func ResetTimer1()
    ResetTimer(0)
EndFunc

Func ResetTimer2()
    ResetTimer(1)
EndFunc

Func ResetTimer3()
    ResetTimer(2)
EndFunc

Func ResetTimer4()
    ResetTimer(3)
EndFunc

Func _Time_Format($ms)
    Local $totsec1 = Int($ms / 1000)         ; ms to sec
    Local $hr1 = Int($totsec1 / 3600)     ; hours
    Local $mn1 = Int(($totsec1 - ($hr1 * 3600)) / 60)     ; minutes
    Local $sc1 = Int(($totsec1 - ($hr1 * 3600) - ($mn1 * 60)))     ; seconds
    Local $tn1 = Int((Int($ms / 100) - ($hr1 * 36000) - ($mn1 * 600) - ($sc1 * 10)))     ; tenths of a second

    Return StringFormat("%02s:%02s:%02s.%01s", $hr1, $mn1, $sc1, $tn1)
EndFunc   ;==>_Time_Format

Timer.au3

Edited by genius257
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...