compute elapsed time

  • Thread starter Thread starter Tcs
  • Start date Start date
T

Tcs

I'd like to display the elapsed time my routine takes (it's big and takes quite
a while). I can capture the start and stop times, but when I computer the
elapsed time, all I get is something like "-2.31481481481555E-04". Does anyone
know what shananigans I need to go thru to get what I'm after? Do I have to
work with the hours, minutes and seconds separately?

Since I composed the above question, I have found the following:

Dim strDisplayTime As String

strDisplayTime = TotalTime \ 60 & ":" & Format(TotalTime Mod 60,
"00")

which I tweaked for my use:

StopTime = Time
ElapsedTime = StartTime - StopTime
strElapsedTime = ElapsedTime \ 60 & ":" & Format(ElapsedTime Mod 60, "00")
MsgBox _
"Stop Time.....(" & StopTime & ")" & vbCrLf & vbCrLf & _
"Start Time.....(" & StartTime & ")" & vbCrLf & vbCrLf & _
" ---------------" & vbCrLf & vbCrLf & _
"Elapsed Time.....(" & strElapsedTime & ")", , "TimeStamp - " & _
Date & " - " & Time

The formatting is okay, I'm now getting "0:00", But even though the elapsed
time is several minutes, all I still get is "0:00". (My elapsed time is very
short right now as I'm still testing.)

Can anyone please help?

Thanks in advance,

Tom
 
Since Time is a fractional part of day, you are getting a decimal (fractional)
part of a day. Also, you are subtracting the larger value from the smaller
value and therefore getting a negative number.

ElapsedSeconds = DateDiff("s",Startime,StopTime)

ElapsedSeconds\60 & ":" & Format(ElapsedSeconds Mod 60,"00")

If you are going to need hours in addition to minutes and seconds, post back.
 
Note the parameter used in the Format function.
This is the key to your problem.

This code waits 2 seconds before proceeding.

Dim intExit As Long, intCurrent As Long
intExit = CLng(Format(Now(), "HHMMSS")) + 2
Do While intCurrent < intExit
intCurrent = CLng(Format(Now(), "HHMMSS"))
Loop

George A
-----Original Message-----
I'd like to display the elapsed time my routine takes (it's big and takes quite
a while). I can capture the start and stop times, but when I computer the
elapsed time, all I get is something like "-
2.31481481481555E-04". Does anyone
 
Back
Top