i am sure all of u guys noticed how Slow is vbtimer
even te shortest delay 1ms is not exactly 1ms it is at least 100 ms ... anyway , what i want is a timer that can
process small intervals of the order of micro seconds
is that possible ?
Printable View
i am sure all of u guys noticed how Slow is vbtimer
even te shortest delay 1ms is not exactly 1ms it is at least 100 ms ... anyway , what i want is a timer that can
process small intervals of the order of micro seconds
is that possible ?
I think using the GetTickCount API will work. There's an example on Fox's programming site, so find one of Fox's posts and click on his programming site.
Nevermind, here it is... :)
http://foxmccloud.tsx.org
Better than that, use the QueryPerformanceCounter and QueryPerformanceFrequency API's the apiviewer declares them like this
but as usual you need to alter this slightly.Code:Public Declare Function QueryPerformanceCounter Lib "kernel32" Alias "QueryPerformanceCounter" (lpPerformanceCount As LARGE_INTEGER) As Long
Public Declare Function QueryPerformanceFrequency Lib "kernel32" Alias "QueryPerformanceFrequency" (lpFrequency As LARGE_INTEGER) As Long
instead of large_integer use currency data types, large integers are 2 longs which makes it hard, the currency is a true Big integer data type, scaled down.
oh, I forgot to tell you how to work them
declare them like this
Query performance counter will put a value into lpperformancecount reperesenting the number of counts since an arbitrary point in time, very much like get tick count but the intervals are faster. Query ferformance frequency puts a value into lpfrequency representing the number of intervals per second, because they're both scaled down you can divide to get a time interval.Code:Public Declare Function QueryPerformanceCounter Lib "kernel32" Alias "QueryPerformanceCounter" (lpPerformanceCount As Currency) As Long
Public Declare Function QueryPerformanceFrequency Lib "kernel32" Alias "QueryPerformanceFrequency" (lpFrequency As Currency) As Long
Here's a code example timing a function MyFunc()
You can convert this into a timer using the same method in Fox's site.Code:
Public sub TimeFunction()
Dim curStartTime as Currency
Dim curFinishTime as Currency
Dim curTimerFreq as currency
dim dblTime as Double
QueryPerformanceCounter curStartTime
MyFunc
QueryPerformanceCounter curFinishTime
QueryPerformaceFrequency curTimerFreq
dblTime = cdbl(curfinishtime - curstarttime) / cdbl(curTimerFreq)
Msgbox "Function Takes " & cStr(dblTime) & " Seconds"
End Sub
[Edited by Sam Finch on 04-29-2000 at 02:09 PM]