THE TIMER CONTROL

The Timer control allows you to perform a task at a specified interval or to wait for a specified length of time.

Timer Example 1

Start a new VB project and place two command buttons and a timer control on the form. Set the properties of the controls as follows:

Command Button: Name = cmdStart; Caption = "Start Timer"

Command Button: Name = cmdStop; Caption = "Stop Timer"

Timer: Name = tmrTest; Enabled = False; Interval = 250

Your form should look something like this:

Consider the following facts about the Timer control:

Place the following declaration in the Form's General Declarations section: Private mintCount As Integer

Code the Click event for the two command buttons and the Timer event for the timer control as follows: Run the program. Click the "Start Timer" button. Messages will appear on the form every quarter of a second.

They will stop when you click the "Stop Timer" button.

A sample run might look like this:

Timer Example 2

The Timer control can be used to make an object on your screen appear to blink. This is done by toggling the Visible property of the object on and off at short intervals. The Visible property is available to nearly all controls; it is a Boolean property that determines whether or not the control is visible to the user at run time by setting its value to True or False (it will always be visible at design time). To build a simple demo, perform the following steps.