VB6 Tutorial 46: Basic Animation

By | 2018-05-08

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.

Properties

The two properties that you’ll want to start off with are Enabled and Interval. There are others, but let’s not muddy the waters. Until later.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

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.

Check out the attached example projects for demonstrations of usage for the timer control, and you’ll see how it can be used for a variety of purposes.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.