-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeReckon.bas
51 lines (33 loc) · 1.38 KB
/
TimeReckon.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Attribute VB_Name = "TimeReckon"
Option Explicit
Dim progressLastChecked, progressLastUpdated
Dim progressTimeSample As New Collection
Dim lastEstimate
Public Function Reckon(index, count)
Dim timeCycle
timeCycle = IIf(index < 1, 0, (Timer - progressLastChecked)) ' a timeCycle is the space from one iteration to the next
If progressTimeSample.count > 5 Then progressTimeSample.Remove (1)
progressTimeSample.Add (timeCycle)
If Timer - progressLastUpdated > 1 Then
lastEstimate = EstimateString(count, index)
progressLastUpdated = Timer
End If
Reckon = lastEstimate
progressLastChecked = Timer
End Function
Function AverageCycle(count, index)
Dim cycleSum, sampleCycle
For Each sampleCycle In progressTimeSample
cycleSum = cycleSum + sampleCycle
Next
AverageCycle = Split(Format(cycleSum / progressTimeSample.count * (count - index) / 86400, "n s"))
End Function
Function EstimateString(count, index)
Dim timeArray
timeArray = AverageCycle(count, index)
If timeArray(0) = 0 And timeArray(1) = 0 Then
EstimateString = "Calculating"
Else
EstimateString = IIf(timeArray(0) <> 0, timeArray(0) & " minutes and ", "") & timeArray(1) & " seconds remaining"
End If
End Function