Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Time capture of less than one second

  Asked By: Steven    Date: Jan 22    Category: MS Office    Views: 928
  

My code has increased in processing time by 33% after installing Windows
SP2. I have the following procedure to measure time in various places in
the code:

Public Sub Record_Stage_Time(Stage_Name As String, Stage_No As Integer)
Range("Title_Stage_" & Stage_No) = Stage_Name
Stage_End_Time = TimeValue(Now())
Range("Title_Stage_" & Stage_No).Offset(, 1) = _
(Stage_End_Time - Stage_Start_Time) * 24 * 60 * 60

Stage_Start_Time = Stage_End_Time
End Sub

In the code I then call it with the following statement, and record the
time on a spreadsheet.

Call Record_Stage_Time("Start of construct reports", 1)

How can I capture times less than 1 second in magnitude in VBA?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Anselma Schmidt     Answered On: Jan 22

Try using Timer if the date information is not important. Timer gives
the number of seconds (including fractions of a second) since
midnight.

Public Sub Record_Stage_Time()
Sheets("Sheet2").Range("C8") = 0 'so you can see it's changed
Stage_Start_Time = Timer
For x = 1 To 75000000 'loop takes 1.4 secs or so
Next
Stage_End_Time = Timer
Sheets("Sheet2").Range("C8") = (Stage_End_Time - Stage_Start_Time)
End Sub

 
Didn't find what you were looking for? Find more on Time capture of less than one second Or get search suggestion and latest updates.




Tagged: