Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer - Showing stop watch time on form 2

Status
Not open for further replies.

jimoo

Programmer
Jun 2, 2003
1,111
US
I want to show a time elapse on a form. The time will continue to show starting at 00:00 and then go up by 1 second intervals: 00:01 = 1 second, 01:01 = 1 minute 1 second, etc..

The timer control is the best option, but how to implement to show the time as I mentioned and stop with the elapse time still showing.



Jim
 
To show time elapsed you need a property holding start datetime, eg add a property starttime to the timer or to the form of the timer.
To compute elapsed time you use elapsedseconds=DATETIME()-thisform.starttime
To display the elapsed time you use whatever you like, eg a label.
To create the display format MM:SS you simply compute m=INT(elapsedseconds/60) for minutes and s=elapsedseconds%60 for seconds. Then put together STR(m,2)+":"+STR(s,2)
To keep the elapsed time showing, when you stop you do nothing. You disable the timer and the label or whatever remains unchanged and shows it's last set caption/value. You may update the display one last time when stopping the timer, so you best put the code of computing and displaying elapsed time in a seperate method you call from the Timer event and from a Stopbutton.Click.
To be able to pause and continue you need more than starttime, but this also depends, what behaviour you want.

Bye, Olaf.
 
Hi,

Olaf's advise will work like a charm, however I would not

quote
compute m=INT(elapsedseconds/60) for minutes and s=elapsedseconds%60 for seconds. Then put together STR(m,2)+":"+STR(s,2)
unquote

Do not use of the single letter m for minutes but abbriviate it to e.g. lMins or lMinutes, s for seconds something like lSecs or lSeconds

Just a minor thing but it may prevent a clash.

Regards,

Jockey
 
OK, Jockey, you catched me one time, I was lazy to use more verbose variable names...

Actually only the first 15 letters have a double meaning as workareas, too, and m is inside that, als there is m., But in the context of using them as variable names a-n also work. It's less good to use a-m as ALIAS names in SQL-Queries, for example. And it's bad style to abbreviate things in general.

Bye, Olaf.
 
Thanks Olaf and Jockey. That did the trick.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top