PDA

Click to See Complete Forum and Search --> : trouble with time remaining


aussiejoe
Jan 25th, 2000, 09:46 AM
i am attempting to make a label which will show the number of seconds remaining before my function finishes. I have it updating a progress bar to 100%, this works fine. i cannot however, get it to work out the correct remaining time. Here is the basic source:

Public Function DoSuch(SomeVar)
sttime = Timer
For i = 1 To SomeVar
ProgBar.Value = 33.3 / SomeVar * i If i Mod 3 = 0 Then
ltime = Timer - sttime
ProgLabel.Caption = ltime / ProgBar.Value * 100 'time so far / % so far * 100
ProgLabel.Refresh
'do some stuff here
Next i
For i = 1 To SomeVar
ProgBar.Value = (33.3 / SomeVar * i) + 33.3
ltime = Timer - sttime
ProgLabel.Caption = ltime / ProgBar.Value * 100
ProgLabel.Refresh
'doing something else here
Next i
For i = 1 To SomeVar
ProgBar.Value = (33.3 / SomeVar * i) + 66.6 ' progressbar
ltime = Timer - sttime
ProgLabel.Caption = ltime / ProgBar.Value * 100
ProgLabel.Refresh
'do final thing here
Next i
End Function


The 3 loops cannot be separated, as they all rely on the previous loops output.
The problem that occurs is that the label which *should* show the seconds remaining, actually counts upwards slowly, rather than down quite quickly. Any ideas or suggestions are welcomed, thanks.

[This message has been edited by aussiejoe (edited 01-25-2000).]

Benj
Jan 26th, 2000, 12:42 AM
This routine is from my timer program which I use to keep myself from burning food while I code. Hope it helps.
Dim lngTime As Long
Dim Minutes As Integer
Dim Seconds As Integer
Private Sub Command1_Click()
'Put the number of minutes here'
lngTime = Text1 * 100
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Minutes = Int(lngTime / 100)
Seconds = lngTime Mod 100
If Seconds > 59 Then Seconds = 59
lngTime = (Minutes * 100) + Seconds
Label1 = Format(lngTime, "00:00")
lngTime = lngTime - 1
If lngTime = 0 Then
Timer1.Enabled = False
'Do Something'
End If
End Sub

Benj
Jan 26th, 2000, 12:45 AM
P.S. Set your timer for 1000 milliseconds, or 1 second. The program will count down every second.