|
-
Sep 20th, 2006, 08:55 AM
#1
Thread Starter
New Member
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
-
Sep 20th, 2006, 09:08 AM
#2
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:
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()
Dim I As Long, lTimer As Long
lTimer = GetTickCount
For I = 1 To 5000
' Your Code
Next I
Debug.Print "Time Taken: " & GetTickCount - lTimer
End Sub
that's good to about 15 milliseconds - if you want more accurate results then you have to use more code (& different API)
-
Sep 20th, 2006, 02:38 PM
#3
Member
Re: Timer
Would it be appropriate to use something like this?
VB Code:
Private Sub Command1_Click()
Dim i As Integer
Dim StartTime, EndTime, ElapsedTime As Single
StartTime = Timer
For i = 1 To 5000
'your code here
Next i
EndTime = Timer
ElapsedTime = EndTime - StartTime
Debug.Print ElapsedTime
End Sub
ElapsedTime should hold the time to the millisecond that the procedure took, yes?
-
Sep 20th, 2006, 04:24 PM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|