Jump to content

timer problem


Recommended Posts

my timer starts ok but after a few ticks it counts down a lot faster

here is my code:

$TIME = TimerInit()

    While 1
        $HOURS = (GUICtrlRead($INPUT_HOURS1)*10)+GUICtrlRead($INPUT_HOURS2)
        $MINUTES = (GUICtrlRead($INPUT_MINUTES1)*10)+GUICtrlRead($INPUT_MINUTES2)
        $SECS = (GUICtrlRead($INPUT_SECONDS1)*10)+GUICtrlRead($INPUT_SECONDS2)
        $TIME_NEW = TimerDiff ($TIME)
        $TIME_NEW = ((($HOURS*3600)+($MINUTES*60)+$SECS)*1000)-$TIME_NEW
        $SECONDS = Round($TIME_NEW/1000)
        $HOURS_REFRESH = Floor($SECONDS/3600)
        $MINUTES_REFRESH = Floor(Mod($SECONDS, 3600)/60)
        $SECONDS_REFRESH = Mod($SECONDS, 60)
        GUICtrlSetData($INPUT_HOURS1, Floor($HOURS_REFRESH/10))
        GUICtrlSetData($INPUT_HOURS2, Mod($HOURS_REFRESH, 10))
        GUICtrlSetData($INPUT_MINUTES1, Floor($MINUTES_REFRESH/10))
        GUICtrlSetData($INPUT_MINUTES2, Mod($MINUTES_REFRESH, 10))
        GUICtrlSetData($INPUT_SECONDS1, Floor($SECONDS_REFRESH/10))
        GUICtrlSetData($INPUT_SECONDS2, Mod($SECONDS_REFRESH, 10))
        Sleep(1000)
    WEnd
Link to comment
Share on other sites

my timer starts ok but after a few ticks it counts down a lot faster

here is my code:

$TIME = TimerInit()

    While 1
        $HOURS = (GUICtrlRead($INPUT_HOURS1)*10)+GUICtrlRead($INPUT_HOURS2)
        $MINUTES = (GUICtrlRead($INPUT_MINUTES1)*10)+GUICtrlRead($INPUT_MINUTES2)
        $SECS = (GUICtrlRead($INPUT_SECONDS1)*10)+GUICtrlRead($INPUT_SECONDS2)
        $TIME_NEW = TimerDiff ($TIME)
        $TIME_NEW = ((($HOURS*3600)+($MINUTES*60)+$SECS)*1000)-$TIME_NEW
        $SECONDS = Round($TIME_NEW/1000)
        $HOURS_REFRESH = Floor($SECONDS/3600)
        $MINUTES_REFRESH = Floor(Mod($SECONDS, 3600)/60)
        $SECONDS_REFRESH = Mod($SECONDS, 60)
        GUICtrlSetData($INPUT_HOURS1, Floor($HOURS_REFRESH/10))
        GUICtrlSetData($INPUT_HOURS2, Mod($HOURS_REFRESH, 10))
        GUICtrlSetData($INPUT_MINUTES1, Floor($MINUTES_REFRESH/10))
        GUICtrlSetData($INPUT_MINUTES2, Mod($MINUTES_REFRESH, 10))
        GUICtrlSetData($INPUT_SECONDS1, Floor($SECONDS_REFRESH/10))
        GUICtrlSetData($INPUT_SECONDS2, Mod($SECONDS_REFRESH, 10))
        Sleep(1000)
    WEnd

I think it's because of an error in your logic.

You have a start time $TIME

you calculate the time left lets say it's CURRENTTIME

You then see how much time has elapsed since $TIME and you take that from CURRENTTIME to give a new CURRENTTIME.

But you should take elapsed time from the very first reading of the set time, not the new current time.

Or, every time you calculate the elapsed time reset $TIME with TimerInit, but I don't think that will be so accurate.

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