vb计算时间差
通过两个变量变为true时的时间差,并以秒显示在TEXT3.TEXT中Dima,b,cPrivateSubTimer1_Timer()IfVNumber1(1)=True...
通过两个变量变为true时的时间差,并以秒显示在TEXT3.TEXT中
Dim a, b, c
Private Sub Timer1_Timer()
If VNumber1(1) = True Then
a = a + 1
If a = 1 Then
a = Hour(Now) * 60 * 60 + Minute(Now) * 60 + Second(Now)
Text1.Text = a
End If
End If
If VNumber1(1) = False Then
a = 0
Text1.Text = ""
End If
If VNumber1(2) = True Then
b = b + 1
If b = 1 Then
b = Hour(Now) * 60 * 60 + Minute(Now) * 60 + Second(Now)
Text2.Text = b
End If
End If
If VNumber1(2) = False Then
b = 0
Text2.Text = ""
End If
If a <> "" And b <> "" Then
c =str(val( b) - val(a))
Text3.Text = c
End If
End Sub
当a和b的值没出来一个时TEXT3.TEXT是一个变值,两个都出来时可得出的TEXT3.TEXT值不准确。 展开
Dim a, b, c
Private Sub Timer1_Timer()
If VNumber1(1) = True Then
a = a + 1
If a = 1 Then
a = Hour(Now) * 60 * 60 + Minute(Now) * 60 + Second(Now)
Text1.Text = a
End If
End If
If VNumber1(1) = False Then
a = 0
Text1.Text = ""
End If
If VNumber1(2) = True Then
b = b + 1
If b = 1 Then
b = Hour(Now) * 60 * 60 + Minute(Now) * 60 + Second(Now)
Text2.Text = b
End If
End If
If VNumber1(2) = False Then
b = 0
Text2.Text = ""
End If
If a <> "" And b <> "" Then
c =str(val( b) - val(a))
Text3.Text = c
End If
End Sub
当a和b的值没出来一个时TEXT3.TEXT是一个变值,两个都出来时可得出的TEXT3.TEXT值不准确。 展开
1个回答
展开全部
貌似你这一大段代码可以用下面三行代码搞定:
Private Sub Timer1_Timer()
Text1.Text = IIf(VNumber1(1), Int(Timer), "")
Text2.Text = IIf(VNumber1(2), Int(Timer), "")
Text3.Text = IIf(VNumber1(1) And VNumber1(2), Val(Text2.Text) - Val(Text1.Text), "")
End Sub
Private Sub Timer1_Timer()
Text1.Text = IIf(VNumber1(1), Int(Timer), "")
Text2.Text = IIf(VNumber1(2), Int(Timer), "")
Text3.Text = IIf(VNumber1(1) And VNumber1(2), Val(Text2.Text) - Val(Text1.Text), "")
End Sub
追问
你写的脚本运行后TEXT1.TEXT和TEXT2.TEXT只是当前的时间(秒),而TEXT3.TEXT运算结果为0
追答
Private Sub Timer1_Timer()
Text1.Text = IIf(VNumber1(1) And Text1.Text = "", Int(Timer), "")
Text2.Text = IIf(VNumber1(2) And Text2.Text = "", Int(Timer), "")
Text3.Text = IIf(Text1.Text "" And Text2.Text "", Val(Text2.Text) - Val(Text1.Text), "")
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询