Calculate remaining time left for an operation

The code example below calculates the time it takes to copy a set interval of documents. Then based on that interval and remaining documents left to copy it estimates how much time is remaining. Currently the interval count is set to 5% of the total number of documents (250 for 5000 docs). It performs the rounding and displays the remaining time in hours and minutes.
LotusScript


'Set parameters for time estimate functionality
Dim TimeEstCounter As Long
TimeEstCounter = 1
Dim CurrentEstimate As String
CurrentEstimate = "Calculating time estimate, please wait..."
'Set interval to 5% of the total doc count
Dim TimeEstInterval As Integer
TimeEstInterval = Round(collect.count * 0.05 , 0)
Set TimeVar1 = New NotesDateTime( Now )	
					
Do 		
	Call sdoc.CopyToDatabase(tdb)
	Set sdoc = collect.GetNextDocument(sdoc)
	newcount = newcount + 1
	If TimeEstCounter = TimeEstInterval Then
		CurrentEstimate = TimeEstimate (collect.count, newcount, TimeVar1, TimeEstInterval)
		'Reset values for next comparison
		TimeEstCounter = 0
		Set TimeVar1 = New NotesDateTime( Now )	
	End If
	TimeEstCounter = TimeEstCounter + 1
	Print newcount & " of " & collect.count & " docs " & typetitleaction & " from " &_
	SourceTitle & " to " & TargetTitle & " (" & CurrentEstimate & ") - " & ErrorCount & " Errors"
Loop Until sdoc Is Nothing


Function TimeEstimate (collectcount As Long, currentcount As Long, TimeVar1, TimeEstInterval As Integer) As String
	
	Set TimeVar2 = New NotesDateTime( Now )
	
	Dim DifferenceInSeconds As Long
	DifferenceInSeconds = TimeVar2.TimeDifference( TimeVar1 )
	
	Dim RemainingDocs As Long
	RemainingDocs = collectcount - currentcount
	
	Dim RemainingMinutes As Long
	RemainingMinutes = Round(((RemainingDocs/TimeEstInterval) * DifferenceInSeconds) /60 , 0) 
	
	If RemainingMinutes < 60 Then
		TimeEstimate = RemainingMinutes & " minutes remaining"
	Else
		RemHours = RemainingMinutes \ 60
		RemMin = RemainingMinutes Mod 60
		TimeEstimate = RemHours & ":" & RemMin & " hours remaining"
	End If
	
End Function

Posted by fbrefere001 on Monday October 14, 2002