Results 1 to 4 of 4

Thread: Stupid VB Timer

  1. #1

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261

    Angry

    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 ?
    - regards -
    - razzaj -

  2. #2
    Guest
    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.

  3. #3
    Guest
    Nevermind, here it is...

    http://foxmccloud.tsx.org

  4. #4
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Better than that, use the QueryPerformanceCounter and QueryPerformanceFrequency API's the apiviewer declares them like this

    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
    but as usual you need to alter this slightly.

    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

    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
    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.

    Here's a code example timing a function MyFunc()

    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
    You can convert this into a timer using the same method in Fox's site.

    [Edited by Sam Finch on 04-29-2000 at 02:09 PM]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width