2012-12-13 17 views
-1

在我的應用程序中,我得到了幾個定時器,timer1也是timer5。 timer1激活timer2等,將前一個定時器設置爲false。vb6檢查是否有多個定時器

,所以我想使後面這些其他定時器,像「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 

末次

任何想法如何做到這一點?

所以..我正在尋找一種方法來檢查所有定時器在一種情況下啓用,並禁用最後一個。

+0

這是措辭不當,請不要解釋它是一半的代碼和一半的邏輯,而是完全解釋邏輯,然後發佈你自己試着寫的代碼。 –

+1

你有沒有考慮過使用控制陣列?然後您將擁有所有具有相同名稱的定時器,但使用Index屬性將它們分開。然後你可以通過索引遍歷集合。 – GTG

回答

0

我不確定你可以同時檢查定時器,但你可以做的是保持所有定時器對應的布爾型字段的數組。

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

然後在每個定時器啓用/禁用事件,你保持這個狀態數組更新。

最後,無論你想要什麼,你都將擁有所有定時器的狀態。

+0

謝謝生病請試試:) 我該如何解決這個問題? –

+0

爲什麼要關閉?它的有效問題 – paragy

+0

我只是認爲人們關閉它時,他們得到了一個指向他們正在尋找什麼,我真的認爲該陣列可能是我想要的解決方案: 但我猜其他人可能有這個問題,只是以另一種方式所以是的,我可以留給他們: –

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