Timer Control


This lesson is about the Timer control in VB6. It's simple and interesting.

Timer control is used to execute lines of code at specific intervals. Using this control, you can create animations without any knowledge of graphics or animation. Though you cannot create some groundbreaking animations using timer control, but it is sufficient for your application. You can create an animated menu for your software. 

This control is not visible at runtime.



Some properties of the Timer control

  • Enabled: To activate or deactivate the timer.
  • Interval: Number of milliseconds between calls  to a timer control's timer event.

For example, set the Interval to 100 , to execute the code in the timer event procedure every 100 milliseconds.

1000 milliseconds = 1 second. 

Example: Now place a Timer control and a CommandButton on the form. Set its Enabled property to False and set the Interval property to 1.

Private Sub cmdStart_Click()
    Timer1.Enabled = True   'Enables the Timer
End Sub
________________________________________________________
Private Sub Timer1_Timer()
    Form1.Width = Form1.Width + 1
End Sub

Now run the program and click on Start button to start the Timer. Once the Timer is enabled, the code in the Timer procedure is executed every 1 millisecond and it increases the width of the current form in the above program example.

Download the following code samples: