新建一工程,拖入一个文本框,一个时钟控件,两个命令按钮。
然后进入代码区,删除所有代码后,粘贴以下代码即可:
Option Explicit
Dim i As Long
Private Sub Command1_Click()
i = Val(Text1.Text)
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1000
Command1.Caption = "开始"
Command2.Caption = "停止"
Text1.Text = "0"
End Sub
Private Sub Timer1_Timer()
i = i + 1
Text1.Text = i
End Sub