Hello,
Personally, I use the windows API instead of a Timer
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
I don't know if it is good or not, but I have been told that the timer
can slow down the computer, so I always use sleep instead of a timer.
You must just pay attention that the sleep will wait 0.1 sec for
example, but if the program between the sleeps last 0.05 sec, you will
have 0.15 seconds between 2 sleeps (the sleep and the following code) so
you must have a fast code between the sleeps (or use multi thread or
multi process)
Marc Allard
Allcomp
William Bub wrote:[color=blue]
> Is there an accurate way to create a "stopwatch" good to 1/10 of a second?
> I'm not sure if I should use the timer control, or some way to access the
> computer timer. I found the following site
>
http://searchvb.techtarget.com/tip/1...535495,00.html
> which has the following:
>
>[color=green]
>>Want to really get down to instants? This tip from reader Phil Lenoir[/color]
>
> tells you how.
>[color=green]
>>--------------------------------------------------------------------------[/color]
>
> ------
>[color=green]
>>The only way you can access fractions of a second in VB is using a Timer,[/color]
>
> Right? Wrong.
>[color=green]
>>Use this simple technique to access time down to the resolution of the PC[/color]
>
> timer interrupt. It
>[color=green]
>>relies on the fact that Microsoft's internal time format is stored as a[/color]
>
> Double-precision number
>[color=green]
>> representing the number of years since 1900.
>>This code will pause for the requested fraction of a second:
>>
>>Public Sub Pause(dblHowLong As Double)
>>Dim dblPauseUntil As Double
>>dblPauseUntil = CDbl(Now) + dblHowLong
>>While cDbl(Now) < dblPauseUntil
>>DoEvents
>>Wend
>>End Sub[/color]
>
>
> I didn't use this directly, but I wanted to see the resolution ofCDbl(Now),
> so I tried
> the following:
>
> Private Sub tmrDispTime_Timer()
> tmrDispTime.Interval = 500
> fNum = fNum + 1
> txtNum = txtNum + CStr(fNum) + vbCrLf
> txtTime = txtTime + CStr(CDbl(Now)) + vbCrLf
> End Sub
>
> I expected this to show a different value every 500ms, but instead I
> received the following for fNum 1-17:
> 38487.9018402778
> 38487.9018402778
> 38487.9018518519
> 38487.9018518519
> 38487.9018634259
> 38487.9018634259
> 38487.901875
> 38487.9018865741
> 38487.9018865741
> 38487.9018981481
> 38487.9018981481
> 38487.9019097222
> 38487.9019097222
> 38487.9019212963
> 38487.9019212963
> 38487.9019328704
> 38487.9019444444
>
> Note that the timer events should come about 2 per second, and that the
> output seems to only change
> approx every other number, i.e. every second.
>
> If I use simply the timer event, and not the clock, how can I expect to
> update a display exactly 10 times per
> second, over 15 minutes or more? If each timer event restarted the timer for
> 100 ms, wouldn't there still be
> time lost between events?
>
>[/color]