Jump to content

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 

Share this post


Link to post
Share on other sites

You missed to set

Global $TIMER = TimerInit()

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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 2019-08-19 - Version 1.4.13.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-07-24 - Version 1.3.6.0) - Download - General Help & Support - Example Scripts - Wiki
Outlook Tools (NEW 2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Taks Scheduler (NEW 2019-10-09 - Version 0.9.0.0) - Download - General Help & Support - Wiki

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

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

 

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

×
×
  • Create New...