Sign in to follow this  
Followers 0
tomagucci

multiple timers in one script

1 post in this topic

#1 ·  Posted (edited)

well I figured out what the problem was in my script, I wanted to open one timer, count down, close it then open another. here is the complete dual timers if anyone is interested. pretty cool if i do say so myself.

#include <GUIConstants.au3>
#include <Date.au3>
Global $timer = TimerInit()
Global $timer2 = TimerInit()
Global $Secs, $Mins, $Hour, $Time, $Time2, $Secs2, $Mins2, $Hour2
Dim $SleepTime = 43000
Dim $SleepTime2 = (43000)

Func SleepTimer()
    
        AdlibEnable("Timer", 50)
        Create()
        While winexists ($sleeptimer)
        $sTime= $time
        $msg = GUIGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
            GUIDelete ($sleeptimer)
            Return
        EndSelect 
        If $sTime = "00:00:00" Then
            GUIDelete ($Sleeptimer)
            Return
        EndIf
        Wend
        Timer()
        sleep ($SleepTime)
        
        
        
EndFunc

func Create()
    Global $sleeptimer = GUICreate("Sleep Time Left (Session 1)",240, 50)
    GUICtrlCreateLabel("00:00:00", 10,10)
        GUISetState(@SW_Show, $sleeptimer)

    
EndFunc


Func Timer()
    _TicksToTime($SleepTime - Int(TimerDiff($Timer)), $Hour, $Mins, $Secs )
    Global $a = Int(TimerDiff($Timer)); save how much is subtracted through TimerDiff *This was the Key*
    Local $sTime = $Time; save current time to be able to test and avoid flicker..
    $Time = StringFormat("%02i:%02i:%02i", $Hour, $Mins, $Secs)
    If $sTime <> $Time Then ControlSetText("Sleep", "", "Static1", $Time)   
EndFunc;Timer 1

Func SleepTimer2()
        AdlibEnable("Timer2", 50)
        
        Create2()
        While WinExists ($sleeptimer2)
            $sTime2 = $time2
        $msg4 = GUIGetMsg()
        Select
        Case $msg4 = $GUI_EVENT_CLOSE
            GUIDelete ($sleeptimer2)
           Return
        EndSelect
        If $sTime2 = "00:00:00" Then
            GUIDelete ($sleeptimer2)
            Return
        EndIf
        Wend
        Timer2()
        sleep ($SleepTime2)
EndFunc
    
func Create2()
    Global $SleepTimer2 = GUICreate ("Sleep Time Left (Session 2)", 240,50)
        GUICtrlCreateLabel("00:00:00", 10,10)
        GUISetState(@SW_Show, $sleeptimer2)
        
    
EndFunc


Func Timer2()
    
    _TicksToTime(($SleepTime2 +$a)- Int(TimerDiff($timer2)), $Hour2, $Mins2, $Secs2)
    Local $sTime2 = $Time2; save current time to be able to test and avoid flicker..
    $Time2 = StringFormat("%02i:%02i:%02i", $Hour2, $Mins2, $Secs2)
    If $sTime2 <> $Time2 Then ControlSetText("Sleep", "", "Static1", $Time2)
    
EndFunc;==>Timer2

dunno if anyone else would ever need such a thing, but yeah, wanted to share with everyone because I was excited that it was the first real thing that I have accomplished in Autoit

edit:

little question, does anyone know how to center the "00:00:00" text?

Edited by tomagucci

Share this post


Link to post
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
Sign in to follow this  
Followers 0