Sign in to follow this  
Followers 0
bomboa

Timers

8 posts in this topic

Ok, so I am having an issue with timers, it works fine and all but....I want to kill the timer in places and restart in other places, is this doable?

Share this post


Link to post
Share on other sites



Ok, so I am having an issue with timers, it works fine and all but....I want to kill the timer in places and restart in other places, is this doable?

Let's see your timer code. I'm sure you can tweak it for that, but hypothetical solutions are all you get for hypothetical code...

:whistle:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Well in AutoIT a timer is just a static string which you later compare against with TimerDiff so you can have as many timers as you want.

Share this post


Link to post
Share on other sites

Well in AutoIT a timer is just a static string which you later compare against with TimerDiff so you can have as many timers as you want.

Yea I realize that, just wondering if there was a start stop function because what I'm doing is running 5 different events at an interval (next event after 10 mins), then looping the 5 events again at the same interval, running script 24/7, so just wondering if I could kill and restart, seems like cleaner way of doing it.

Share this post


Link to post
Share on other sites

Can you please tell me how can I pause a timer?

e.g. it count from 00:01,00:02 to 00:10 then I pause it.

After a moment I restart it and it can resume. Start from 00:11

And how can I make a timer to start to count in a specify time? e.g. start from 00:01:00?

For easy understanding. I want to modfy the example script from help

Thanks

; *** Demo to show a timer window

#include <GUIConstants.au3>

#include <Date.au3>

opt("TrayIconDebug",1)

Global $Secs, $Mins, $Hour, $Time

;Create GUI

GUICreate("Timer",120, 50)

GUICtrlCreateLabel("00:00:00", 10,10)

GUISetState()

;Start timer

$timer = TimerInit()

AdlibEnable("Timer", 50)

;

While 1

;FileWriteLine("debug.log",@min & ":" & @sec & " ==> before")

$msg = GUIGetMsg()

;FileWriteLine("debug.log",@min & ":" & @sec & " ==> after")

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

EndSelect

Wend

;

Func Timer()

_TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs )

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("Timer", "", "Static1", $Time)

EndFunc ;==>Timer

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Can you please tell me how can I pause a timer?

e.g. it count from 00:01,00:02 to 00:10 then I pause it.

After a moment I restart it and it can resume. Start from 00:11

And how can I make a timer to start to count in a specify time? e.g. start from 00:01:00?

For easy understanding. I want to modfy the example script from help

Thanks

; *** Demo to show a timer window

#include <GUIConstants.au3>

#include <Date.au3>

opt("TrayIconDebug",1)

Global $Secs, $Mins, $Hour, $Time

;Create GUI

GUICreate("Timer",120, 50)

GUICtrlCreateLabel("00:00:00", 10,10)

GUISetState()

;Start timer

$timer = TimerInit()

AdlibEnable("Timer", 50)

;

While 1

;FileWriteLine("debug.log",@min & ":" & @sec & " ==> before")

$msg = GUIGetMsg()

;FileWriteLine("debug.log",@min & ":" & @sec & " ==> after")

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

EndSelect

Wend

;

Func Timer()

_TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs )

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("Timer", "", "Static1", $Time)

EndFunc ;==>Timer

Here is how you can suspend the timer.

#include <GUIConstants.au3>
#include <Date.au3>
Global $suspendcount=0,$paused = False,$pausestart=0
opt("TrayIconDebug",1)
Global $Secs, $Mins, $Hour, $Time
;Create GUI
GUICreate("Timer",120, 90)
GUICtrlCreateLabel("00:00:00", 10,10)
$pause = GUICtrlCreateButton("suspend",10,30)
$restart = GUICtrlCreateButton("continue",10,60)
GUISetState()
;Start timer
$timer = TimerInit()
AdlibEnable("Timer", 50)
;
While 1
;FileWriteLine("debug.log",@min & ":" & @sec & " ==> before")
$msg = GUIGetMsg()
;FileWriteLine("debug.log",@min & ":" & @sec & " ==> after")
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $pause
    $paused = True;
    $pausestart = TimerDiff($timer)
Case $msg = $restart
    $suspendcount += TimerDiff($timer) - $pausestart
    $paused = False
EndSelect
Wend
;
Func Timer()
    If $paused Then Return
_TicksToTime(Int(TimerDiff($timer)-$suspendcount), $Hour, $Mins, $Secs )
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("Timer", "", "Static1", $Time)
EndFunc;==>Timer

To start the timer at some time in the future you just need to decide how long to wait befoe the timer should start, convert that time to ticks, and in your timer function add some code that looks at the timerdiff value and if it's smaller than your calculated delay then return, ie leave the setting at 0:0:0. Then when the timerdiff value is big enough the function operates as now, except that you will need to subtract the calculated value from the tics value.

If you understood that rambling then well done. Bit pushed for time atm.

Another way would be to set AdLIbEnable to operate a different function at some time equal to your delay. Then in that function change AdLibEnable to your timer function. Probably a better idea.

Third way, you could set an independant timer to start off the adlibenable; search for SetTimer and KillTimer, but these methods might not be the best approach for you.

Edited by martin

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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