Timer Control for Visual Basic 6.0 Users
The Timer control in Visual Basic 6.0 is replaced by the Timer component in Visual Basic 2008. The names of some properties and events are different, and in some cases there are differences in behavior.
The Visual Basic 6.0 Timer control is an actual control that is sited on a form at design time; however it is not visible at run time.
The Visual Basic 2008 Timer is a component that is added to the tray at design time; as a component it has no Parent property.
In Visual Basic 6.0, you can disable a Timer control by setting the Interval property to 0.
In Visual Basic 2008, the lower range for the Interval property is 1. If you set the interval to 0, it throws a run-time exception. The Visual Basic 2008 Timer component uses the Enabled property to allow you to disable or enable it.
The following examples illustrate differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008.
Code Changes for Starting and Stopping a Timer Control
The following code demonstrates how to enable and disable a Timer control at run time.
' Visual Basic 6.0 Public Function TimerOn(Interval As Integer) If Interval > 0 Then ' Start the timer. Timer1.Interval = Interval Else ' Stop the timer. Timer1.Interval = 0 End If End Function
The following table lists Visual Basic 6.0 properties and events, along with their Visual Basic 2008 equivalents. Those properties and events that have the same name and behavior are not listed.
This table provides links to topics explaining behavior differences. Where there is no direct equivalent in Visual Basic 2008, links are provided to topics that present alternatives.
Properties and Events
Visual Basic 6.0
Visual Basic 2008 Equivalent
New implementation. For more information, see Control Arrays for Visual Basic 6.0 Users
The behavior of the Interval property has changed. For more information, see Timer Interval property behavior has changed.
New implementation. The Timer is a component and cannot have a parent.