Monday, February 2, 2009

Processbar in Notes: Calculate the remaing time

Just wrote an agent to update a lot of documents - included this code to calculate the remaining time:

Dim t As Variant 'the current time
t = Getthreadinfo( 6 )

Dim cnt As Long 'the current index

Dim max As Integer 'the total number of documents to update
max = coll.Count


dim est as double 'the estimated time left

est = Clng( (((Getthreadinfo( 6 )-t ) / Getthreadinfo( 7 )) / cnt ) * (max-cnt)) 'time left in seconds
If est > 60 Then
Print Cint(( cnt / max ) * 1000 ) / 10 & "% (" & est \ 60 & " min left)"
Else
Print Cint(( cnt / max ) * 1000 ) / 10 & "% (" & est & " seconds left)"
End If


Notice the use of / and \. The forward slash does a normal floating point calculation - the backslash does a integer division: 3/2 = 1,5 and 3\2 = 1

2 comments:

Theo Heselmans (Xceed) said...

Interesting. Tx for the code.
2 questions: where is 'max' defined ? Shouldn't it be 'total' ?
Why the disclaimer ?

Jakob Majkilde said...

Fixed the typos - thanx :-)
Disclaimer came from the email I sent to the blog - now it's deleted ....

 
Creative Commons License
This work is licensed under a Creative Commons Attribution 3.0 Unported License.