求大神帮我注释下下面代码(VBA excel)

Public StopIt AsBoolean
Public ResetIt As Boolean
Public LastTime
Private Sub CommandButton1_Click()
Dim StartTime, FinishTime, TotalTime, PauseTime
StopIt = False
ResetIt = False
If Range("b8") = 0 Then
StartTime = Timer
PauseTime = 0
LastTime = 0
Else
StartTime = 0
PauseTime = Timer
End If

StartIt:
DoEvents
If StopIt = True Then
LastTime= TotalTime
Exit Sub
Else
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("b8").Value = Format(hh, "00") & ":"& Format(MM, "00") & ":" & Format(SS,"00") & "." & Format(HM, "00")
IfResetIt = True Then
Range("b8") = Format(0, "00") & ":"& Format(0, "00") & ":" & Format(0,"00") & "." & Format(0, "00")
LastTime = 0
PauseTime = 0
End
End If
GoToStartIt
End If
End Sub
Private SubCommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByValX As Single, ByVal Y As Single)
StopIt = True
End Sub
Private SubCommandButton3_Click()
Range("b8").Value = Format(0, "00") & ":"& Format(0, "00") & ":" & Format(0,"00") & "." & Format(0, "00")
LastTime = 0
ResetIt = True
End Sub

第1个回答  推荐于2016-08-15
是一个计时程序呢。

Public StopIt AsBoolean
Public ResetIt As Boolean
Public LastTime
Private Sub CommandButton1_Click()
Dim StartTime, FinishTime, TotalTime, PauseTime
StopIt = False
ResetIt = False
If Range("b8") = 0 Then
StartTime = Timer '点下开始时间
PauseTime = 0 '暂停时间
LastTime = 0 '结束时间
Else
StartTime = 0
PauseTime = Timer
End If

当开始点下时,开始时间为目前时间

StartIt:
DoEvents
If StopIt = True Then ‘ 停止
LastTime= TotalTime
Exit Sub
Else
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("b8").Value = Format(hh, "00") & ":"& Format(MM, "00") & ":" & Format(SS,"00") & "." & Format(HM, "00")
IfResetIt = True Then
Range("b8") = Format(0, "00") & ":"& Format(0, "00") & ":" & Format(0,"00") & "." & Format(0, "00")
LastTime = 0
PauseTime = 0
End
End If
GoToStartIt
End If
End Sub
Private SubCommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByValX As Single, ByVal Y As Single)
StopIt = True
End Sub
Private SubCommandButton3_Click()
Range("b8").Value = Format(0, "00") & ":"& Format(0, "00") & ":" & Format(0,"00") & "." & Format(0, "00") ‘显示的格式
LastTime = 0
ResetIt = True
End Sub追问

能不能更详细点啊,把主要功能都注释下,谢谢啊!!

追答

你需要那一部分的吧,一行一行的来还是一功能一个功能的来?

追问

整个程序,按一个功能一个功能的来,谢谢了!

追答

Public StopIt AsBoolean
Public ResetIt As Boolean
Public LastTime

Private Sub CommandButton1_Click()
Dim StartTime, FinishTime, TotalTime, PauseTime
StopIt = False
ResetIt = False
If Range("b8") = 0 Then
StartTime = Timer '点下开始时间
PauseTime = 0 '暂停时间
LastTime = 0 '结束时间
以上为当开始点下时,开始时间为目前时间,就是开始计时。
Else
StartTime = 0
PauseTime = Timer
End If
以上为暂停

StartIt:
DoEvents
If StopIt = True Then ‘ 停止
LastTime= TotalTime
Exit Sub
以上为停止计时
Else
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("b8").Value = Format(hh, "00") & ":"& Format(MM, "00") & ":" & Format(SS,"00") & "." & Format(HM, "00")
以上为显示用时
IfResetIt = True Then
Range("b8") = Format(0, "00") & ":"& Format(0, "00") & ":" & Format(0,"00") & "." & Format(0, "00")
LastTime = 0
PauseTime = 0
以上为计时归零

追问

谢谢

本回答被提问者采纳
相似回答