-1

在我的应用程序中,我有几个计时器,timer1 太 timer5。timer1 激活 timer2 等等,将前一个计时器设置为 false。

所以我想制作另一个跟随这些的计时器,比如“timer6”

if timer1.enabled = true then 'then it should check if the timer2 now is enabled
if timer2.enabled = true then 'and so on to it reaches timer5..

需要任何示例来实现这一点,因为我在一个停止点,基本上只需要这部分工作。

我的想法只是在 timer6 中执行此操作

if timer1.enabled = true then
  if timer2.enabled = true then
    if etc etc

    else 

      timer6.enabled = true
      timer6.enabled = false

    end if
  end if
end if

结束子

任何想法如何做到这一点?

所以..我正在寻找一种方法来检查所有计时器是否在一个条件下启用并禁用最后一个。

4

2 回答 2

0

我不确定您是否可以一次检查所有计时器,但您可以做的是保留所有计时器对应的布尔字段的数组。

 array = collection[timerState{timer1,true},timerState{timer2,false}] 

然后在每个计时器启用/禁用事件上,您保持此状态数组更新。

最后,无论您想要什么,您都将拥有所有计时器的状态。

于 2012-12-13T10:46:57.680 回答
0

看看下面的测试项目

单击表单启动第一个计时器,单击按钮检查哪个计时器处于活动状态

'1 form with
'    1 timer : name=Timer1    Index=0
'    1 command button : name=Command1
Option Explicit

Private Sub Form_Load()
  Dim intIndex As Integer
  Timer1(0).Enabled = False
  Timer1(0).Interval = 1000
  For intIndex = 1 To 5
    Load Timer1(intIndex)
    Timer1(intIndex).Interval = intIndex * 1000
  Next intIndex
End Sub

Private Sub Form_Click()
  Timer1(0).Enabled = True
End Sub

Private Sub Timer1_Timer(Index As Integer)
  Print CStr(Now)
  Timer1(Index).Enabled = False
  If Index < Timer1.Count - 1 Then
    Timer1(Index + 1).Enabled = True
  Else
    Print "done"
  End If
End Sub

Private Sub Command1_Click()
  Dim intIndex As Integer
  For intIndex = 0 To Timer1.Count - 1
    If Timer1(intIndex).Enabled Then
      Caption = "active timer : " & CStr(intIndex)
      Exit For
    End If
  Next intIndex
End Sub
于 2012-12-19T11:29:49.877 回答