Library tutorials & articles

Timer control

Examples

For both of these examples, you need a label (called lblMsg) and a timer called tmrEvent.

Count Down Example

This example counts down from 10 when the form is loaded.

Private lngCountDownValue As Long '// variable that stores countdown value

Private Sub Form_Load()
    lngCountDownValue = 10 '// count down from 10
    tmrEvent.Interval = 1000 '// 1 second
    '// call the timer now for the first interval
    '// (otherwise we would have to wait 1 second)
    Call tmrEvent_Timer
    tmrEvent.Enabled = True '// timer is enabled
End Sub

Private Sub tmrEvent_Timer()
    lngCountDownValue = lngCountDownValue - 1 '// decrement the value
    lblMsg.Caption = lngCountDownValue & " seconds remaining"
    If lngCountDownValue = 0 Then
        '// time expired
        '// do not allow this procedure to call again.
        tmrEvent.Enabled = False
        Msgbox "Time has expired"
    End If 
End Sub

Clock Example

This example displays a clock.

Private Sub Form_Load()
    tmrEvent.Interval = 1000 '// 1 second
    '// call the timer now for the first interval
    '// (otherwise we would have to wait 1 second)
    Call tmrEvent_Timer
    tmrEvent.Enabled = True '// timer is enabled
End Sub

Private Sub tmrEvent_Timer()
    '// update the time

    lblMsg.Caption = "Time: " & Time()
End Sub

Comments

  1. 09 Jul 2006 at 08:34

    Hi!

    I created a control that I named KYNOUAJAXContainer that can be found at http://www.kynou.com/KYNOUControls/KYNOUControls.zip. This control allows you to add regular ASP.NET controls into it and they all become AJAX enabled. You can use this container control as a sort of timer control for ASP.NET. This is because the container control has a property called ShouldRefresh. When this property is set to true, it will refresh the content of all the controls inside of the container every RefreshInterval seconds (RefreshInterval is another property of the container control).
    I posted tutorials that will walk you through the steps to use the control at http://www.KYNOU.com under the Tutorial Index => Ajax => KYNOU AJAX Controls link

  2. 25 May 2005 at 08:36

    How could i make a timer activate every 3 hours to check the database and findout any new records were added?


    Thanks in advance


    E.Screw

  3. 24 May 2002 at 02:46

    Sometimes, if the timer doesn't fire, one can try putting in a doevents statement. [Someone's got any experience with that one?]

  4. 01 Jan 1999 at 00:00

    This thread is for discussions of Timer control.

Leave a comment

Sign in or Join us (it's free).

James Crowley James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audience ...

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback