请解析一下一段vba代码,代码是关于设置计时器的
PrivateSubCommandButton1_Click()DimStartTime,FinishTime,TotalTime,PauseTimeIfRange("a...
Private Sub CommandButton1_Click()
Dim StartTime, FinishTime, TotalTime, PauseTime
If Range("a1") = 0 Then
StartTime = Timer
PauseTime = 0
LastTime = 0
Else
StartTime = 0
PauseTime = Timer
End If
StartIt: DoEvents
FinishTime = Timer
TotalTime = FinishTime - StartTime + LastTime - PauseTime
TTime = TotalTime * 100
HM = TTime Mod 100
TTime = TTime \ 100
hh = TTime \ 3600
TTime = TTime Mod 3600
MM = TTime \ 60
SS = TTime Mod 60
Range("a1").Value = Format(hh, "00") & ":" & Format(MM, "00") & ":" & Format(SS, "00") & "." & Format(HM, "00")
GoTo StartIt
End Sub 展开
Dim StartTime, FinishTime, TotalTime, PauseTime
If Range("a1") = 0 Then
StartTime = Timer
PauseTime = 0
LastTime = 0
Else
StartTime = 0
PauseTime = Timer
End If
StartIt: DoEvents
FinishTime = Timer
TotalTime = FinishTime - StartTime + LastTime - PauseTime
TTime = TotalTime * 100
HM = TTime Mod 100
TTime = TTime \ 100
hh = TTime \ 3600
TTime = TTime Mod 3600
MM = TTime \ 60
SS = TTime Mod 60
Range("a1").Value = Format(hh, "00") & ":" & Format(MM, "00") & ":" & Format(SS, "00") & "." & Format(HM, "00")
GoTo StartIt
End Sub 展开
1个回答
展开全部
#计时器的VBA代码解析#
-------【如有疑问,可加新浪微博@芐雨】------
Private Sub CommandButton1_Click()
Dim StartTime, FinishTime, TotalTime, PauseTime, LastTime '定义四个变量分别是开始时间(StartTime),完成时间(FinishTime),总计时间(TotalTime),停止时间(PauseTime),持续时间(LastTime)
If Range("a1") = 0 Then '如果A1单元格=0时
StartTime = Timer '开始时间为现在的时间,timer为现在时间
PauseTime = 0 '完成时间为0
LastTime = 0 '持续时间为0
Else '如果A1单元格不等于0时
StartTime = 0 '开始时间为0
PauseTime = Timer '停止时间为现在的时间
End If
StartIt: DoEvents '标签:StartIt
FinishTime = Timer '完成时间=现在时间
TotalTime = FinishTime - StartTime + LastTime - PauseTime '总计时间=完成时间-开始时间+持续时间-停止时间
TTime = TotalTime * 100 'TTime=总计时间*100 ,
HM = TTime Mod 100 'HM = TTime Mod 100,相除的余数,如 6 mod 4=2
TTime = TTime \ 100 '整数除法,如: 6 \ 4=1 ,下面同理
hh = TTime \ 3600
TTime = TTime Mod 3600
MM = TTime \ 60
SS = TTime Mod 60
Range("a1").Value = Format(hh, "00") & ":" & Format(MM, "00") & ":" & Format(SS, "00") & "." & Format(HM, "00") '单元格A1等于:XXX,Format是设置格式,&是连接符
GoTo StartIt '回到标签:StartIt
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询