Timer Event

See AlsoG4EZL0              Example14OMJUWN>Low               Example24OMJUWO>Low

Applies To

Timer3MVR08J.

Description

Occurs when a preset interval for a timer control has elapsed.  The interval's frequency is stored in the control's Interval3LX7YRY property, which specifies the length of time in milliseconds.2NN1IWE

Syntax

Sub ctlname_Timer ([Index As Integer])

Remarks

The argument Index uniquely identifies a control if it is in a control array8G7Y0UU.  Use this procedure to tell Visual Basic what to do at every timer Interval.  When you are working with the Timer event:

         The Interval property specifies the interval between Timer events in milliseconds.

         Whenever the timer control's Enabled3XD4FN property is set to True and the Interval is greater than zero, the Timer event waits for the period specified in the Interval property.


See Also

Help:

Enabled Property3XD4FN

Interval Property3LX7YRY

Timer FunctionQ3GPQ6

 

Programmer's Guide:

Chapter 17, "Interacting with the Environment"


Timer Event Example 1

The example demonstrates a digital clock.  To try this example, paste the code into the Declarations section of a form that contains a label and a timer control.  Then press F5.

Sub Form_Load ()

   Timer1.Interval = 1000                ' Set timer interval.

End Sub

 

Sub Timer1_Timer ()

   Label1.Caption = Time                 ' Update time display.

End Sub


Timer Event Example 2

This example moves a picture box across a form.  To try this example, paste the code into the Declarations section of a form that contains a timer and a picture control.  Then press F5.  For a better visual effect you can assign a bitmap to the picture box using the Picture property.

Dim DeltaX, DeltaY As Integer            ' Declare variables.

Sub Timer1_Timer ()

   Picture1.Move Picture1.Left + Deltax, Picture1.Top + DeltaY

   If Picture1.Left < ScaleLeft Then DeltaX = 100

   If Picture1.Left + Picture1.Width > ScaleWidth + ScaleLeft Then

      DeltaX = -100

   End If

   If Picture1.Top < ScaleTop Then DeltaY = 100

   If Picture1.Top + Picture1.Height > ScaleHeight + ScaleTop Then

      DeltaY = -100

   End If

End Sub

 

Sub Form_Load ()

   Timer1.Interval = 1000                ' Set Interval.

   DeltaX = 100                          ' Initialize variables.

   DeltaY = 100

End Sub