Dim t As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
t = t - 1
t = 5
If t = 0 Then
Timer1.Enabled = False
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Int(Rnd * (100000))
End Sub
我想在5秒的时候让数字停下来,这代码怎么改
你的T值放在放在timer事件里,否则进入到timer后根本就不会执行t-1操作,另外t的初始化应该放在窗体加载事件中,更改后的代码如下:
Option Explicit
Dim t As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
t = 5
End Sub
Private Sub Timer1_Timer()
t = t - 1
If t = 0 Then
Timer1.Enabled = False
End If
Label1.Caption = Int(Rnd * (100000))
End Sub
Dim t, b As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
t = t - 1
t = 5
If t = 0 Then
Timer1.Enabled = False
End If
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
b = b + 1
Label1.Caption = Int(Rnd * (100000))
If b = 5 Then
Timer1.Enabled = False
End If
End Sub
看看是不是这样
这样:
Dim t As Integer
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
t = 5
Timer1.Enabled = False
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Int(Rnd * (100000))
t = t - 1
If t = 0 Then
Timer1.Enabled = False
End If
End Sub