Monday, October 4, 2010

Visual Basic Date and Time Function : Interval

Purpose : The Interval property of a timer control indicates the length of time to wait before processing the Timer event. This property can be changed at design time or runtime. Each timer control's Interval property is independent of the Interval properties of other timer controls on the same form.

Syntax :
[ forrm! ].Name.Interval = milliseconds&

Form : Name property of the form
Name : Name property of the timer control being affected
milliseconds& : Amount of time that must pass between triggerings of the Timer event ( as a long integer )

Setting of the Interval property
Value : Effect
0 : Disables the timer (default)
1-65535 : Milliseconds between triggerings ; 1000 = 1 second

The Timer control's Enabled property determines whether the control responds to the passage of time. Set Enabled to False to turn a Timer control off, and to True to turn it on. When a Timer control is enabled, its countdown always starts from the value of its Interval property setting.

Option Explicit
Private Sub Form_Load()
Timer1.Interval = 900 ' Set interval.
HScroll1.Min = 100 ' Set minimum.
HScroll1.Max = 900 ' Set maximum.
End Sub
Private Sub HScroll1_Change()
' Set interval according to scroll bar value.
Timer1.Interval = 1000 - HScroll1.Value
End Sub
Private Sub Timer1_Timer()
' Switch BackColor between red and blue.
If Picture1.BackColor = RGB(255, 0, 0) Then
Picture1.BackColor = RGB(0, 0, 255)
Else
Picture1.BackColor = RGB(255, 0, 0)
End If
End Sub

No comments:

Post a Comment