Results 1 to 4 of 4

Thread: Timer

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2006
    Posts
    9

    Timer

    Hi
    I want to count time to execute the following loop.
    Suppose
    For i=1 To 5000
    ...........
    .........
    next i

    would you please let me know how could I use the timer to count that time.

    Thanks a lot.
    Razzaqul

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Timer

    are you talking about measuring the time it takes to execute the loop?

    if so, don't use a timer - do something like this:
    VB Code:
    1. Private Declare Function GetTickCount Lib "kernel32" () As Long
    2.  
    3. Private Sub Command1_Click()
    4.     Dim I As Long, lTimer As Long
    5.    
    6.     lTimer = GetTickCount
    7.     For I = 1 To 5000
    8.         ' Your Code
    9.     Next I
    10.     Debug.Print "Time Taken: " & GetTickCount - lTimer
    11. End Sub
    that's good to about 15 milliseconds - if you want more accurate results then you have to use more code (& different API)

  3. #3
    Member
    Join Date
    Sep 2006
    Posts
    37

    Re: Timer

    Would it be appropriate to use something like this?

    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim i As Integer
    3.     Dim StartTime, EndTime, ElapsedTime As Single
    4.     StartTime = Timer
    5.     For i = 1 To 5000
    6.         'your code here
    7.     Next i
    8.     EndTime = Timer
    9.     ElapsedTime = EndTime - StartTime
    10.     Debug.Print ElapsedTime
    11. End Sub

    ElapsedTime should hold the time to the millisecond that the procedure took, yes?

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Timer

    The timer has a granularity of 1ms (can be set to the nearest ms), but its accuracy is about 50ms +/- any routines that keep it from getting clock ticks - so GetTickCount is 3 times as accurate if nothing else is running, and better if something is.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

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