我詳細說明一下,我想用vb6.0做出一個用timer控制的label,這個label會以亂數的形式,倒數計時到0之後,又回到亂數,再到數計時,比如說一開始出現亂數5,倒數5 4 3 2 1 0後,自動再產生另一亂數3,倒數 3 2 1 0,再產生另一亂數9,類似這樣的情形。
以下是倒數計時timer程式碼
Private Sub Timer6_Timer()
Randomize
Sec6 = Val(Label6.Caption) - 1
Label6.Caption = Str(Sec6)
If Sec6 < 0 Then Label6.Caption = Int(Rnd * 59)
End Sub
問題來了,我想用另外一個label,將倒數計時出現零的次數,累加到label上,不支該如何寫,我弄到快哭了
NewLabel.Caption= Val(NewLabel.Caption) + 1
像這樣:
Private Sub Timer6_Timer()
Randomize
Sec6 = Val(Label6.Caption) - 1
Label6.Caption = Str(Sec6)
If Sec6 < 0 Then Label6.Caption = Int(Rnd * 59)
NewLabel.Caption= Val(NewLabel.Caption) + 1
End Sub
Label1.Caption = -1
Timer6.Interval = 500
Timer6.Enabled = True
End Sub
Private Sub Timer6_Timer()
Timer6.Enabled = False
Randomize
Sec6 = Val(Label6.Caption) - 1
Label6.Caption = Str(Sec6)
If Sec6 < 0 Then
Label6.Caption = Int(Rnd * 59)
Label1.Caption = Label1.Caption + 1
End If
Timer6.Enabled = True
End Sub