Time Remaining in Process

J

josh.mallett

I have a lengthy process which takes upwards of an hour to complete.
For simplicity, simply assume it is a basic Do While loop which takes
approximately an hour to complete. I have added a progress bar to my
form to show the progress, but I was curious if there was any way to
list an estimated remaining time? I had tried to use something like
the code listed below but it doesn't give the expected results
(probably because it's overly simple). Any help would be greatly
appreciated!

dteTimeStart = Time

Do While CurrentCountInLoop <= MaxCountOfLoop
dteTimeElapsed = Time - dteTimeStart * 24 * 60 * 60
dteTimeRemaining = dteTimeElapsed * MaxCountOfLoop /
CurrentCountInLoop
Loop

Thanks,
Josh
 
S

strive4peace

Hi Josh,

it actually looks pretty clever ... perhaps instead of evaluating it
every iteration, though, maybe every 1% or so ...

what kind of results does it give?

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
E

Ed Metcalfe

Josh,

A couple of comments on your code so far:

Time() only returns to the nearest whole second, which may not give the
necessary level of precision for your calculation. I have used Timer() as
this returns hundreds of a second for greater accuracy.

It would also be worthwhile calculating the time taken to run a certain
number of iterations, and then work out the average time for a single
iteration. This will allow for a single iteration taking less than 1/100th
second.

This is my attempt - it can probably be tidied up and simplified.


Public Sub TimeExample()
Dim sngStartMeasure As Single
Dim sngEndMeasure As Single
Dim lngCounter As Long
Dim dblTimeSingleIteration As Double
Dim dteTimeRemaining As Date
Const lngMaxIterations As Long = 100000000 'Number of loops to go
through.
Const lngIterationsToMeasure As Long = 10000000 'Number of loops to
time. This needs to be
'high enough to give a sensible result.

sngStartMeasure = Timer()
lngCounter = 1

Do While lngCounter <= lngMaxIterations
'The main body of the loop will go in here to be
'executed before the time estimation calcs
If lngCounter = lngIterationsToMeasure Then 'Time the first few
iterations, then estimate time needed to complete
sngEndMeasure = Timer()
dblTimeSingleIteration = ((sngEndMeasure - sngStartMeasure) /
lngIterationsToMeasure)

If lngCounter >= lngIterationsToMeasure Then 'Only calculate
remaining time if we have calculated time for a single iteration
dteTimeRemaining = CDate(Format(dblTimeSingleIteration *
(lngMaxIterations - lngCounter) / 86400, "hh:nn:ss"))
End If
End If

lngCounter = lngCounter + 1
Loop
End Sub


Ed Metcalfe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top