为什么我vb中的timer控件只能执行两次?
PrivateSubCommand1_Click()Timer1.Enabled=TrueEndSubPrivateSubCommand2_Click()Timer1.E...
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim a As Long
a = 1
If a >= 1 Then
a = a + 1
Label1.Caption = a
End If
End Sub 展开
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim a As Long
a = 1
If a >= 1 Then
a = a + 1
Label1.Caption = a
End If
End Sub 展开
1个回答
展开全部
Dim a As Long '解决方法:定义为全局变量
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
a = 1 '在这里初始化
End Sub
Private Sub Timer1_Timer()
'Dim a As Long
'a = 1 '并不是因为时钟执行两次,是因为这里你使用了局部变量,每次执行时重新定义a并赋值为1
If a >= 1 Then
a = a + 1
Label1.Caption = a
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询