Results 1 to 6 of 6

Thread: Timer

  1. #1

    Thread Starter
    Registered User
    Join Date
    May 2001
    Posts
    61

    Timer

    Hello,

    I need to put a timer into an app that counts down from from xx amount of seconds. Can this be done? I'm just learning this stuff as I go.

    Thanks,
    Gabe

    [email protected]

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    I threw this together. Is it what you are looking for ?
    Place a timer control, label, textBox, and commandButton on the form. Then just paste the code below into your form. Enter the number of seconds into the textbox, click the command button, and the timer will count backwards to zero and display the results in the label.
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Label1.Caption = Text1.Text
        Timer1.Enabled = True
    End Sub
    
    Private Sub Form_Load()
        Timer1.Interval = 1000
        Timer1.Enabled = False
    End Sub
    
    Private Sub Timer1_Timer()
        Label1.Caption = Label1.Caption - 1
        If Label1.Caption = 0 Then
            Timer1.Enabled = False
        End If
    End Sub

  3. #3
    Addicted Member
    Join Date
    May 2000
    Location
    England
    Posts
    135
    Well, if you put a timer on the form and then just set the timer interval to 1 second and then have a counter loop just to count down each time the timer restarts. Maybe like this :

    timer1.interval = ???
    let x=10

    then in the timer1 code :
    let x=x-1
    if x = 0 then ?????

    then code to restart timer and it will countdown until 0, I think!
    I can do the code, if you want it - hope this helps

  4. #4
    AIS_DK
    Guest
    Put a normal timer control on your form, set it's interval to the amout of seconds you wan't and enable it.

    It will then raise an event, when en xx seconds has passed. On the event just disable it.

    The timer control however has some limitations, so if it is a long time, that you wan't counted down, you will need to use the timers lying inside windows.

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    or...
    Code:
    Private Sub Form_Load()
        Timer1.Enabled = True
        Timer1.Interval = 1000  'approx 1 second
    End Sub
    
    Private Sub Timer1_Timer()
        Dim iCount As Integer
        Static x As Integer
        iCount = 10
        If x >= 1 Then
          iCount = 10 - x
        End If
        Print iCount
        x = x + 1
        If iCount = 0 Then MsgBox "10 seconds"
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6

    Thread Starter
    Registered User
    Join Date
    May 2001
    Posts
    61
    Sweet. That should do it. Thanks.

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