Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse API functions to create a timer that can wait as long as 23 days between events
DescriptionA normal Visual Basic Timer control can only wait 65,535 milliseconds or about 65 seconds. This example shows how to use API functions to create a timer that can wait as long as 23 days between events in Visual Basic 6.
KeywordsTimer, Timer control, time, speed, performance
CategoriesControls, API
 
The CmdStart button's Click event handler determines whether the timer is running. If the timer is running, the code uses KillTimer to stop it. If the timer is not running, the code uses SetTimer to start it. Because the timer's delay is specified in milliseconds as a long integer, the delay can be more than 23 days.
 
Private TimerID As Long

' Start or stop the timer. See also Form_Unload.
Private Sub CmdStart_Click()
Static running As Boolean
Dim pause As Long

    If running Then
        ' Stop the timer.
        KillTimer 0, TimerID
        CmdStart.Caption = "Start"
        RunningLabel.Caption = "Stopped"
    Else
        ' Start the timer.
        pause = CLng(PauseText.Text)
        TimerID = SetTimer(0, 0, pause, _
            AddressOf MyTimer)
        CmdStart.Caption = "Stop"
        RunningLabel.Caption = "Running"
    End If
    running = Not running
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated