我的努力没有结果,到目前为止,我所拥有的是,
Private Sub Timeperpart_Timer()
secs = secs + 1
If secs = 60 Then
mins = mins + 1
secs = 0
End If
If mins = 60 Then
hrs = hrs + 1
mins = 0
End If
If secs < 10 Then
Lbltime.Caption = CStr(hrs & ":" & mins & ":" & 0 & CStr(secs))
End If
If mins < 10 Then
ElseIf secs < 10 Then
Lbltime.Caption = CStr(hrs & ":" & 0 & CStr(mins) & ":" & 0 & CStr(secs))
Else
Lbltime.Caption = CStr(hrs & ":" & 0 & CStr(mins) & ":" & secs)
End If
If hrs < 10 Then
ElseIf mins < 10 Then
ElseIf secs < 10 Then
Lbltime.Caption = CStr(0 & CStr(hrs) & ":" & 0 & CStr(mins) & ":" & 0 & CStr(secs))
End If
If hrs < 10 Then
ElseIf mins < 10 Then
ElseIf secs > 10 Then
Lbltime.Caption = CStr(0 & CStr(hrs) & ":" & 0 & CStr(mins) & ":" & secs)
End If
If hrs < 10 Then
ElseIf mins > 10 Then
ElseIf secs > 10 Then
Lbltime.Caption = CStr(0 & CStr(hrs) & ":" & mins & ":" & secs)
End If
End Sub问题是,在行if mins < 10 then中,如果mins是0,程序将不会将mins识别为小于10,然后不会添加前导零,与小时相同。我正在寻找一种可行的方法,或者说,任何方法都可以做到。
发布于 2014-06-03 13:47:12
将所有这些代码替换为:
Lbltime.Caption = Format$(TimeSerial(hrs, mins, secs), "hh:mm:ss")实际上,还可以将所有hrs mins secs加法逻辑替换为:
Dim the_time As Date
....
the_time = DateAdd("s", 1, the_time)所以最终你会:
Private the_time As Date
Private Sub Timeperpart_Timer()
the_time = DateAdd("s", 1, the_time)
Lbltime.Caption = Format$(the_time, "hh:mm:ss")
End Subhttps://stackoverflow.com/questions/24016836
复制相似问题