Time counter

Recommended Posts

Sure, just use a variable. Declare it somewhere (say auto-start sequence:)

global timecounter

Then when you want the time to start do:

timecounter = systime()

and wherever it is displayed, put:

SysTime() - timecounter

Use formattime() to display in H:m:s:

formattime(systime()- timecounter)

or formatdatetime() if you want more control over the display.

If you want an accumulating counter, you'll need two variables:

global timecounter = 0
global totaltime = 0

to start counting do:

timecounter = systime()

to display do:

formatdatetime("%H:%M:%S", (systime()-timecounter) * (timecounter != 0) + totaltime)

This uses a little boolean math to only include the running time (timecounter) part when the counter is counting.

to stop counting do:

totaltime += systime() - timecounter
timecounter = 0

to reset do (when timer is stopped):

totaltime = 0

Link to comment
Share on other sites

  • 3 years later...

Hi Guru,

I'm sorry to bump an old thread, but after employing this code on a new project, I observed the result changing after a few seconds of a stop. Let me explain:

The timer starts perfectly, pauses perfectly when a pause my system, but upon a stop, the value changes to something resembling the systime. For example,

During a test at around 5:15 in the afternoon, the timer result changed from 00:01:26 to 17:16:26 within a few seconds of stopping the operation. Subsequent tests repeated.

Any ideas?


Link to comment
Share on other sites

Its going to display totalTime when you stop (when you set timecounter to 0). If you set timecounter to 0 before you update totalTime, it could throw it. Anyhow, look at your variables, totalTime and timeCounter and see if they are absolute times or relative times. Absolute times will be on the order of 1 billion. Relative would be in the tens of thousands maybe.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.