VB 5, Using the Multimedia timer of Windows from winmm.dll, you may have a
resolution of 1 millisecond and this timer is not stopped when a form is
moved or a modal dialog box is open. I noticed only a small jitter of +-
1ms, when I programmed an interval of 250 ms, I got sometimes 249 or 251
ms, but most intervals were 250 ms long.
Here is a short example, but write each declare on a single line. The
Callback function possible with VB5 is used here.
' declarations in a code module
Public Const TIME_ONESHOT = 0
Public Const TIME_PERIODIC = 1
Declare Function timeKillEvent Lib "winmm.dll" (ByVal uID As Long) As Long
Declare Function timeSetEvent Lib "winmm.dll" (ByVal uDelay As Long,
ByVal uResolution As Long, ByVal lpFunction As Long, ByVal dwUser As
Long, ByVal uFlags As Long) As Long
Public FID&
' the Callback function within the code module
Sub TimeCallback(TimerID%, Msg%, dwUser&, dw1&, dw2&)
Static i&
i = i + 1
End Sub
' and now the code for the form load and unload events
Private Sub Form_Load()
Show
FID = timeSetEvent(250, 0, AddressOf TimeCallback, 0, TIME_PERIODIC)
End Sub
Private Sub Form_Unload(Cancel As Integer)
If FID <> 0 Then timeKillEvent FID
End Sub
I tested it, it works great!
Submitted by:
Uwe Hercksen
For EMail response, please replace nospam with zew
'--------------------------------------------------'
HTH
--
Henri
remove "MyName"
: In my application I need a timer-interval of 100 ms. I found it is not
: very accurate. Trying to 'tune' the timer to aquire a acceptable
: inaccuracy caused the accuracy to change in steps; not gradually!
: I think the problem is that Vb uses the system timer (runs at 18.2
: Hz) to control it's timer.
:
: Is there a way to increase timer accuracy.
:
: I do use VB3.0 and W3.11
:
: Greetings, H. Luijmes
: