VBGood网站全文搜索 Google

首页 - 经验之谈 - 使Timer控件超过1分钟
发表评论(0)作者:不详, 平台:VB6.0+Win98, 阅读:12862, 日期:2000-11-08
Use the Timer control for longer than 1 minute

As you know, the Timer control provides a great way to schedule events in a Visual Basic project. When you enable the control, it fires off its Timer event every n milliseconds, as determined by the TimeInterval property. However, the TimeInterval property only accepts numbers up to 65,535, or just over one minute. As a result, you may have wondered how to use this control for periods longer than that. To do so, use a form, or project level, variable to keep track of how many times the Timer event fires. Then, in the Timer event, re-enable the control if enough time hasn注释:t passed. For example, consider the code below that we attached to a standard form.

Option Explicit
Dim iElapsedMin As Integer
Const cMax_Min As Integer = 2

Private Sub Form_Load()
Timer1.Enabled = True
iElapsedMin = 1
End Sub

Private Sub Timer1_Timer()
lblText.Visible = (iElapsedMin = cMax_Min)
Timer1.Enabled = (iElapsedMin < cMax_Min)
iElapsedMin = iElapsedMin + 1
End Sub