FredixBlog


Just my log about anything I could find enjoyable.



Display a counter and remaining time in a loop

author Posted by: fredometro on date May 25th, 2007 | filed 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")

No related posts.

     Add A Comment

You must be logged in to post a comment.


Warning: include(/home/www/web421/html/phpTraffic/write_logs.php) [function.include]: failed to open stream: No such file or directory in /home/websitef/public_html/fredometro.com/wp-content/themes/blueshadow/footer.php on line 15

Warning: include() [function.include]: Failed opening '/home/www/web421/html/phpTraffic/write_logs.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/websitef/public_html/fredometro.com/wp-content/themes/blueshadow/footer.php on line 15