Indiaum

Zombie Timer?

7 posts in this topic

 

 

Hi guys, 
 
I'm new to AutoIt and i need a explanation on Timers, because something is happening and i can't understand why.
 
I need a timer, so i did:
Global $TIMER = 0
Global $TIMERDIFF = 0

Main()

Func Main()
    While 1
    $TIMERDIFF = Round(TimerDiff($TIMER) / 1000, 1)

            ToolTip($TIMERDIFF, 100, 100, "Info", 1, 1)
        WEnd
    WEnd
EndFunc 

Share this post


Link to post
Share on other sites



Welcome to AutoIt and the forum!

You first need to initialize the timer using TimerInit.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Thank you very much for the extremely fast response. 

It was intentional, i thought that i could keep a timer stopped, and only use the TimerInit() to start it in a specific moment.

After the TimerInit(), is it possible to stop it?

Share this post


Link to post
Share on other sites

TimerInit / TimerDiff are not something that runs, to stop.

It just compares two time stamps, yours might be from 1971 or something.

You needa to Sleep() too.

Global $TIMER = TimerInit()
Global $TIMERDIFF = 0

Main()

Func Main()
    While 1
    $TIMERDIFF = Round(TimerDiff($TIMER) / 1000, 1)

            ToolTip($TIMERDIFF, 100, 100, "Info", 1, 1)
Sleep(10)
        WEnd
    WEnd
EndFunc

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

 

TimerInit / TimerDiff are not something that runs, to stop.

It just compares two time stamps, yours might be from 1971 or something.

You needa to Sleep() too.

Global $TIMER = TimerInit()
Global $TIMERDIFF = 0

Main()

Func Main()
    While 1
    $TIMERDIFF = Round(TimerDiff($TIMER) / 1000, 1)

            ToolTip($TIMERDIFF, 100, 100, "Info", 1, 1)
Sleep(10)
        WEnd
    WEnd
EndFunc

I see, thank you.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

 

It was intentional, i thought that i could keep a timer stopped, and only use the TimerInit() to start it in a specific moment.

 

After the TimerInit(), is it possible to stop it?

 

If I have interpreted this correctly you just want to keep a running time that can be started and stopped.  And timerinit can get by for this task (you are just starting it over and adding it to the last value),  search 'stopwatch' on the forums, but here is a crude example that will keep a running total of how long the gui has spent with the Start button pressed:

#include <GUIConstantsEx.au3>

Global $TIMER = 0
Global $LastTime = 0

GUICreate("Test" , 400 , 400)
$ButtonStart = GUICtrlCreateButton("START" , 10 , 100)
$ButtonStop = GUICtrlCreateButton("STOP" , 100 , 100)
GUICtrlSetState($ButtonStop , $GUI_DISABLE)
$edit = GuiCtrlCreateEdit ("" , 200 , 1 , 200 , 400)
GUISetState(@SW_SHOW)

while 1

Switch GUIGetMsg()
    Case $ButtonStart
        GUICtrlSetState($ButtonStop , $GUI_ENABLE)
        GUICtrlSetState($ButtonStart , $GUI_DISABLE)
        Main()
    Case $ButtonStop
        GUICtrlSetState($ButtonStop , $GUI_DISABLE)
        GUICtrlSetState($ButtonStart , $GUI_ENABLE)
        Stop()
    Case -3
        exit
EndSwitch

wend

Func Main()
    $TIMER = TimerInit()
EndFunc

Func Stop()
    $RunningTime = Round(TimerDiff($TIMER) / 1000, 1)
    $TotalTime = $LastTime + $RunningTime
    GUICtrlSetData($edit , GuiCtrlRead($edit) & $TotalTime & @CRLF)
    $LastTime = $TotalTime
EndFunc
Edited by boththose

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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