vb关于timer做计时器的问题

来源:百度知道 编辑:UC知道 时间:2024/06/28 05:49:43
我想做一个计时器,大致要求如下:
有label1,label2,label3
点击lable1,label1显示当前时间,label3显示0:0:0以秒为单位开始跳
点击label2,label2显示当前时间,label3显示两次点击经过的时间并停止计时,类似一个体育课上用的秒表
求代码,谢谢

Dim Starttime As Date, Endtime As Date, OK As Boolean

Private Sub Form_Load()
Label1.Caption = "开始时间" '初始Label的Caption(标题)为"开始时间"
Label2.Caption = "结束时间"
Label3.Caption = "累计时间"
End Sub

Private Sub Label1_Click()
OK = False
Starttime = Now '取得当前时间值
Label1.Caption = Format(Starttime, "hh:mm:ss") '时间格式显示
Call PassTime
End Sub

Private Sub Label2_Click()
Endtime = Now '取得当前时间值
Label2.Caption = Format(Endtime, "hh:mm:ss") 'hh:mm:ss为24小时制
OK = True
End Sub
Sub PassTime() '累计经过时间
Do Until OK = True '做循环,直到"OK"为"真"结束循环, 即OK=True
Label3 = Format((Now - Starttime), "hh:mm:ss") '用当前时间减去开始时间
DoEvents
Loop
End Sub

'=========楼上版加注解版==========

Dim t1 As Date, t2 As Date, f As Boolean

Private Sub Label1_Click()
f = F