用VB编写一个秒表

来源:百度知道 编辑:UC知道 时间:2024/05/22 14:57:45
如何用vb编写一个秒表呢?
要从00:00 开始 要看到数字在跳动的
好的加分

'一个标签,两个按钮,一个计时器。
'标签显示时间,按钮一控制秒表,按钮二清零。

Dim m As Integer, s As Integer, ms As Integer, flag As Boolean
Private Sub Command1_Click()
If flag = False Then
Timer1.Interval = 10
flag = True
Else
Timer1.Interval = 0
flag = False
End If
End Sub

Private Sub Command2_Click()
flag = False
Timer1.Interval = 0
m = 0
s = 0
ms = 0
Label1.Caption = "00:00:00"
End Sub

Private Sub Timer1_Timer()
ms = ms + 1
If ms = 100 Then
s = s + 1
ms = 0
End If
If s = 60 Then
m = m + 1
s = 0
End If
Label1.Caption = Format(m, "00:") & Format(s, "00:") & Format(ms, "00")
End Sub

1)
启动visual basic6.0 ,打开一个新的标准工程。
2)
在窗体上Form1上添加6个标签空间(Label) 2个命令按钮(CommandButton)和1个计时器(Timer)。命令按钮的Caption属性分别为“启动”“停止”
Timer1的Interval属性为10
Label1 Label2 Label3的Caption属性分别为“开始时间”“