Results 1 to 3 of 3

Thread: trouble with time remaining

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2000
    Location
    MFAU
    Posts
    19

    Post

    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:
    Code:
    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).]

  2. #2
    New Member
    Join Date
    Jan 1999
    Posts
    7

    Post

    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

  3. #3
    New Member
    Join Date
    Jan 1999
    Posts
    7

    Post

    P.S. Set your timer for 1000 milliseconds, or 1 second. The program will count down every second.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width