Click to See Complete Forum and Search --> : visual basic and the clock
ibennetch
June 12th, 2001, 04:49 PM
I'm looking for a way to make a stopwatch or something similar in visual basic. the problem is I want to be able to run it in the background, but if I do that using a timer, the time goes off because of a lower priority. any thoughts? perhaps tie it to the system clock?
furlong47
June 12th, 2001, 05:14 PM
Isaac--I'm writing a stopwatch right now <IMG SRC="smilies/biggrin.gif" border="0"> <IMG SRC="smilies/biggrin.gif" border="0"> Something to run on my new laptop for Newsbreak, so I don't have to wrestle with all those timers <IMG SRC="smilies/wink.gif" border="0">. I think I'm having a similar problem as you are--it gets off by about three seconds every minute. I'm afraid when I transfer it to my laptop, which is a slower machine, it'll get off by even more. E-mail me if you wanna compare notes; and if anybody has any ideas I could use them <IMG SRC="smilies/smile.gif" border="0">
opiate
June 12th, 2001, 11:23 PM
Why aren't use using the system clock?
Just curious...
ibennetch
June 13th, 2001, 07:26 AM
Originally posted by opiate:
<STRONG>Why aren't use using the system clock?
Just curious...</STRONG>
very simply because I don't know how...I've only had an introductory level class in visual basic and we didn't cover that. I wasn't sure if it was possible; you seem to have answered that. NOw I just have to go figure out how ;-)
antonye
June 13th, 2001, 08:03 AM
Here's an example routine.
You need to fill in your bits between the two, or chop it up into functions so that you can trigger the Start and Stop, for example using the _OnClick events of a button.
dim dtmStart as Date
dim dtmStop as Date
dim sDelay as String
dtmStart = Now()
... do stuff ...
dtmStop = Now()
sDelay = DateDiff("s",dtmStart,dtmStop)
MsgBox "That took " & sDelay & " seconds."
This routine uses the DateDiff (http://msdn.microsoft.com/library/officedev/office97/output/F1/D6/S5B207.HTM) function to format the difference between two date objects.
The Now() function simply returns a timestamp of the system date and time.
HTH.
ibennetch
June 13th, 2001, 11:08 AM
thanks antonye, that does the job!