Display a counter and remaining time in a loop
Posted by: fredometro on
May 25th, 2007 |
Filed under: MS-Access
When browsing thru records, a while/wend loop can take a long time to execute, depending on the number of records, communication speed and complexity of the process.
Here is a snippet that displays a counter, including estimated remaining time. After a few records browsed thru the loop, a rather accurate estimate of the remaining time can be displayed.
' Declarations
Dim starttime
Dim elapsedtime
Dim estimatedtime
Dim count
Dim counttot
Dim estHours, estMinutes, estSeconds
' Initializations: Code to be pasted BEFORE the while/wend loop
count = 0
counttot = ... 'whichever way you could get the number of records to be processed: DCOUNT, VIEW,
'rs.RecordCount...
starttime = Now()
' Displaying the count: Code to be pasted at the end of the loop, when jumping to the next record
count = count + 1
elapsedtime = DateDiff("s", starttime, Now())
estimatedtime = elapsedtime / (count + 0.00001) ' time for one record
estimatedtime = estimatedtime * (counttot - count) ' time for remaining records
estHours = Int(estimatedtime / 3600)
estMinutes = Int((estimatedtime - 3600 * estHours) / 60)
estSeconds = Int(estimatedtime - (60 * estMinutes))
If count / 100 = Int(count / 100) Then Echo True, "Uploading " & SourceTable & " on " & Get_rawmeasuresDb(CurrentDb.Name) & " : " & count & "/" & counttot & " records processed " & " Remaining: " & Format(TimeSerial(estHours, estMinutes, estSeconds), "hh:mm:ss")

Be the first!
Tags: