|
本帖最后由 blueblank 于 2018-12-19 09:13 编辑
要求自定义循环时间,现在使用的是OR的方式判断等于当前时间整5分钟执行一次,但是不知道怎么设计倒计时Label1中的显示内容(用当前获取的分钟减自定义刷新时间,精确到几分几秒),比如说刷新时间设置为5分钟(不是间隔5分钟,是当前时间运行到0,5,15,20,25。。。到55来执行),那么当然获取的时间分钟数有可能是0-59的整5,一共10个数来判断,应该如何改,请指教:Dim D As Boolean
Dim tz
Private Sub CommandButton1_Click()
D = True
tz = "1"
End Sub
Private Sub UserForm_Activate()
Call 窗体
End Sub
Sub 窗体()
Dim t!, temp, 自定义刷新分钟, H0%, M0%, S0%, H1%, M1%, S1%
自定义刷新分钟 = 5
If tz = "1" Then
Exit Sub
End If
t = Timer
H0 = Hour(Time): M0 = Minute(Time): S0 = Second(Time)
Do
DoEvents
H1 = Hour(Time)
M1 = Minute(Time)
S1 = Second(Time)
With Me.Label1
.Caption = "告警刷新:0" & TimeSerial(H0 - H1, (M0 - M1), (S0 - S1))
.Left = (Me.Width - .Width) / 2
.Left = 1
.Font.Size = 10
Me.Label1.ForeColor = RGB(255, 0, 0) ' 改变成红色
End With
With Me.Label2
.Caption = "当前时间:" & Time
.Left = (Me.Width - .Width) / 2
.Font.Size = 10
.Left = 1
End With
' Loop Until D = True Or Timer - t > 20
Loop Until D = True Or M1 = 5 Or M1 = 10 Or M1 = 15 Or M1 = 20 Or M1 = 25 Or M1 = 30 Or M1 = 35 Or M1 = 40 Or M1 = 45 Or M1 = 50 Or M1 = 55 Or M1 = 0
temp = TimeSerial(H1 - H0, M1 - M0, S1 - S0)
With Me.Label3
.Caption = "每5分钟执行1次"
End With
D = False
End
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Cancel = True
D = True
End Sub
|
|