-
Apr 16th, 2012, 01:19 PM
#1
Thread Starter
New Member
[RESOLVED] Timing VB Code
I was wondering if someone knows if there is some type of VB Timer that will time how long your code runs for. I ask this because i am looking for a way to optimize the speed of my code.
-
Apr 16th, 2012, 02:56 PM
#2
Addicted Member
Re: Timing VB Code
Hi,
To measure time in seconds (and parts of seconds) you can use Timer function. This function returns seconds from Midnight.
Code:
Sub TestTime()
Dim sStartTime As Single
Dim sEndTime As Single
'Stores start time
sStartTime = Timer
'Place your code here
'Stores end time
sEndTime = Timer
'Show execution time
Debug.Print "Execution time in seconds: ", sEndTime - sStartTime
End Sub
Hope this helps.
Regards,
using VB 2010 .NET Framework 4.0; MS Office 2010; SQL Server 2008 R2 Express Edition | Remember to mark resolved threads and rate useful posts.
-
Apr 16th, 2012, 05:16 PM
#3
New Member
Re: Timing VB Code
Hi,
I have used the method Sweet Dreams suggests very effectively in the past to do exactly what you want to do.
Regards,
-
Apr 16th, 2012, 10:40 PM
#4
Hyperactive Member
Re: Timing VB Code
There is also the TimeGetTime() API function which is very accurate
-
Apr 18th, 2012, 11:44 PM
#5
Member
Re: Timing VB Code
The code I have used in the past to do this is:
Code:
Private Declare Function GetTickCount Lib "kernel32.dll"() As Long
Private Sub Time_Code()
Dim t as 'Long
t = GetTickCount
'Put code to be timed here
MsgBox "Code took " & GetTickCount - t & _
" milliseconds to run.", vbInformation, "Time Taken"
End Sub
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
|