Accuracy of timers in VB? 
Author Message
 Accuracy of timers in VB?

Any suggestions about the accuracy of timers in VB? (using VB2)

In theory the following code should print a message every 60 secs.
In practice it prints a message once every 61-62 secs if I do
absolutely nothing else; if I keep Windows quite busy doing other
stuff
(nothing very compute-bound; just tapping away at an editor, or
checking
through fles via file manager) I get messages ever 65-90 seconds.

Does anyone know any way to get more accurate timings
(like maybe +-5 secs) out of VB?

Let me guess: use a timer, but when it times out sample system time
with Time or Time$.  Do unpleasant messing to subtract starting time
from
latest value returned by Time.

-----------------------------

Sub Form_Load ()

rem m%, n% are Dimmed for form

  m% = 0
  n% = 0

  Show
  form1.Print Time$

End Sub
___________________________________

Sub Timer1_Timer ()

rem Timer1 has Interval of 1000

 n% = n% + 1
 If n% = 59 Then

  n% = 0
  form1.Print Time$

  m% = m% + 1
  If m% = 6 Then End

 End If

End Sub

Yours,

Alan Campbell
Brighton, UK

<<<<<<<<<<<<<<<<<<<<<<     >>>>>>>>>>>>>>>>>>>



Sat, 03 Jan 1998 03:00:00 GMT  
 Accuracy of timers in VB?
Don't know if this is exactly what you want but have a look at the 'Timer'
FUNCTION.
Also to calculate the difference between two times try the 'DateDiff' function.


Sat, 03 Jan 1998 03:00:00 GMT  
 Accuracy of timers in VB?

Quote:

> In theory the following code should print a message every 60 secs.
> In practice it prints a message once every 61-62 secs if I do
> absolutely nothing else; if I keep Windows quite busy doing other
> stuff
> (nothing very compute-bound; just tapping away at an editor, or
> checking
> through fles via file manager) I get messages ever 65-90 seconds.

> Does anyone know any way to get more accurate timings
> (like maybe +-5 secs) out of VB?

1. Declare the following function somewhere
        Declare Function GetCurrentTime& Lib "User"

2. In your form load event try this

Dim nCounter as long

nCounter = GetCurrentTime()

        :
        :
        :
        :       any startup code you may have
        :      
        :
Do while doevents()
        if GetCurrentTime() > nCurrentTime + 60000 then
                nCurrentTime = getCurrentTime()
                : Do your thing here
        Endif
Loop

The Do loop will not interfere with the normal operation of your form, but is a great deal more
accurate than a timer control.

Have fun,

Peter  



Fri, 09 Jan 1998 03:00:00 GMT  
 Accuracy of timers in VB?


Quote:


Campbell) writes:

> > In theory the following code should print a message every 60 secs.
> > In practice it prints a message once every 61-62 secs if I do
> > absolutely nothing else; if I keep Windows quite busy doing other
> > stuff
> > (nothing very compute-bound; just tapping away at an editor, or
> > checking
> > through fles via file manager) I get messages ever 65-90 seconds.

> > Does anyone know any way to get more accurate timings
> > (like maybe +-5 secs) out of VB?

> 1. Declare the following function somewhere
> Declare Function GetCurrentTime& Lib "User"

> 2. In your form load event try this

> Dim nCounter as long

> nCounter = GetCurrentTime()

> :
> :
> :
> :any startup code you may have
> :
> :
> Do while doevents()
> if GetCurrentTime() > nCurrentTime + 60000 then
> nCurrentTime = getCurrentTime()
> : Do your thing here
> Endif
> Loop

> The Do loop will not interfere with the normal operation of your form,

but is a great deal more

Quote:
> accurate than a timer control.

> Have fun,

> Peter

If you want Windows to respond, not just your App, include a DoEvents
statement in the loop.

Jens
--
  -------------------------------------------------------------------------
 |  Jens Balchen jr.         |  I came, I saw, I answered.                 |
 |  Innocent Software        |                                             |
 |  P.O. Box 6052            |    - Julius Cesar                           |
 |  N-4638 Kristiansand      |                                             |
  -------------------------------------------------------------------------



Sat, 10 Jan 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. vb timer accuracy ???

2. Timer, accuracy in millisecs!

3. Timer Function Accuracy

4. Timer Accuracy - Help !

5. Accuracy of Timers in VB5

6. Timer with high accuracy

7. Timer Accuracy

8. Wanted: VB3 Timer with millisecond accuracy.

9. Timer accuracy??? -RFH ( Request for Help)

10. timer accuracy of mmsystem.dll

11. Timer accuracy

12. Timer accuracy

 

 
Powered by phpBB® Forum Software