desmclean
asked on
Timer Resolution
Hi,
I tried implementing the following timer code so I could get a better timer resolution than the inbuilt Timer control in VB which is 55ms. This code measuers the time interval between each timer event. When excuted the resulting time is 110ms on one computer and 55ms on another computer. I need to know is this timer interval correct, Is my code at fault (Is it giving the correct interval). If the code is correct and the timer can only pole at 55ms, it then any other timer that can pole at a higher fequency say 5 to 10 ms.
The following is my timer code ------
In A Module
Public Sub TimerCallback(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
Call Form1.TimerCall
End Sub
In Form1
Option Explicit
Private Declare Function GetTickCount Lib "Kernel32" () As Long
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Dim Counter As Single
Dim StartTime As Double
Dim FinishTime As Double
Private Sub Command1_Click()
Call SetTimer(Me.hwnd, CLng(1), 50, AddressOf TimerCallback)
End Sub
Private Sub Form_Load()
Counter = 0
End Sub
Public Sub TimerCall()
Dim lngTimerID As Long
Static FirstSD As Boolean
If Not FirstSD Then
FirstSD = True
StartTime = GetTickCount
End If
Counter = Counter + 1
If Counter = 2 Then
Label1.Caption = GetTickCount - StartTime
KillTimer Me.hwnd, CLng(1)
FirstSD = False
End If
End Sub
-------------------------- ---------- ---------- ----
I would be grateful for any advice regarding this problem.
Is there other way of determining the timers frequency.
I tried implementing the following timer code so I could get a better timer resolution than the inbuilt Timer control in VB which is 55ms. This code measuers the time interval between each timer event. When excuted the resulting time is 110ms on one computer and 55ms on another computer. I need to know is this timer interval correct, Is my code at fault (Is it giving the correct interval). If the code is correct and the timer can only pole at 55ms, it then any other timer that can pole at a higher fequency say 5 to 10 ms.
The following is my timer code ------
In A Module
Public Sub TimerCallback(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
Call Form1.TimerCall
End Sub
In Form1
Option Explicit
Private Declare Function GetTickCount Lib "Kernel32" () As Long
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Dim Counter As Single
Dim StartTime As Double
Dim FinishTime As Double
Private Sub Command1_Click()
Call SetTimer(Me.hwnd, CLng(1), 50, AddressOf TimerCallback)
End Sub
Private Sub Form_Load()
Counter = 0
End Sub
Public Sub TimerCall()
Dim lngTimerID As Long
Static FirstSD As Boolean
If Not FirstSD Then
FirstSD = True
StartTime = GetTickCount
End If
Counter = Counter + 1
If Counter = 2 Then
Label1.Caption = GetTickCount - StartTime
KillTimer Me.hwnd, CLng(1)
FirstSD = False
End If
End Sub
--------------------------
I would be grateful for any advice regarding this problem.
Is there other way of determining the timers frequency.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Help for QueryPerformanceCounter:
http://www.google.com/search?q=site:microsoft.com+QueryPerformanceCounter&btnI=
Help for QueryPerformanceFrequency:
http://www.google.com/search?q=site:microsoft.com+QueryPerformanceFrequency&btnI=