VB6's Timer control is useful in almost any situation when you want something to happen after a set interval or on a regular basis. This can help save you a lot of time when you want to schedule a task in advance.
To access the Timer control, go to the VB toolbox and look for the pocket watch icon. There are two properties you will need to set when working with the Timer control:
When you actually put a Timer control on a form, it's visible but will not be seen when the program runs. Also, it's important to know that the Timer control's single event, Timer, fires each time the Timer counts down from Interval.
Follow these steps to schedule tasks using a Timer control:
A Timer control will cycle repeatedly as long as its Enabled property is True. To run it just once, set Enabled to False in the Timer event procedure. You can have two or more Timer controls on a form. In fact, cascading two Timer controls is the only way to time intervals longer than about 65 seconds.
Note: In theory, the Timer control's resolution is one millisecond; however, the reality is it's not that good, so you shouldn't use it for time-critical tasks.
Advance your scripting skills to the next level with TechRepublic's free Visual Basic newsletter, delivered each Friday. Automatically sign up today!