Results 1 to 2 of 2

Thread: If a timer is set to go off every X seconds, how do i show time left b4 it executes?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195

    Question If a timer is set to go off every X seconds, how do i show time left b4 it executes?

    If a timer is set to go off 10000 milliseconds (10 seconds), how can i display how much time is left before its executed?

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Instead of setting the interval to 10000, set it to 1000 (1 second) and use a static variable to count how many seconds it's been. This example requires a timer (Timer1) and a label (Label1):

    VB Code:
    1. Private Sub Form_Load()
    2.   Timer1.Interval = 1000
    3.   Label1.Caption = "10 seconds remaining."
    4. End Sub
    5.  
    6. Private Sub Timer1_Timer()
    7. Static num As Integer
    8.  
    9.   num = num + 1
    10.   If num = 10 Then
    11.     'do your stuff here
    12.     MsgBox "10 seconds is up"
    13.     num = 1
    14.     Label1.Caption = 10
    15.   Else
    16.     Label1.Caption = 10 - num & " seconds remaining."
    17.   End If
    18. End Sub
    My evil laugh has a squeak in it.

    kristopherwilson.com

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