Jump to content

Zombie Timer?


Recommended Posts

 

 

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 
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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?

Link to comment
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.

Link to comment
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.

Link to comment
Share on other sites

 

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

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

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...