Option Explicit
Private Declare Function QueryPerformanceFrequency Lib "kernel32" (lpFrequency As Currency) As Long
Private Declare Function QueryPerformanceCounter Lib "kernel32" (lpPerformanceCount As Currency) As Long
Dim cTFreq As Currency
Dim cTStart As Currency
Dim cTEnd As Currency
Private Sub Form_Load()
Dim T As Single
QueryPerformanceFrequency cTFreq 'Generally the frequency of your processor
QueryPerformanceCounter cTStart 'Generally the number of cycles of your processor
Wait 0.001
QueryPerformanceCounter cTEnd
T = (cTEnd - cTStart) / cTFreq 'cycles / frequency = time
Debug.Print "And that took " & Round(T, 4) & " seconds"
End Sub
Public Sub Wait(ByVal sSeconds As Single)
Dim T1 As Currency, T2 As Currency
QueryPerformanceCounter T1
T1 = T1 + sSeconds * cTFreq
Do
DoEvents 'Comment out for more accuracy, leave in if waiting for long periods
QueryPerformanceCounter T2
Loop Until T2 => T1
End Sub