vb中的dateadd函数 急!!!!!!!!

来源:百度知道 编辑:UC知道 时间:2024/06/04 08:50:27
Option Explicit
Dim dat As Date
Dim t As Integer

Private Sub Form_Load()
Timer1.Interval = 100
dat = Now
t = 0

End Sub

Private Sub Timer1_Timer()

If Now = DateAdd("s", 2, dat) Then
t = t + 1
Label1.Caption = Str(t)
dat = Now
End If

End Sub

为什么t的值为1时就不再变化了。而我设想的是t应该从0开始每隔两秒增加1的

Option Explicit
Dim dat As Date
Dim t As Integer
Private Sub Form_Load()
Timer1.Interval =2000
End Sub
Private Sub Timer1_Timer()
t = t + 1
End Sub

就可以完成你说的两秒加一次
Timer1.Interval = 2000

至于你的当T变为1时就不真要变化主查因为dateadd函数在运行时你的两个时间已经超过了2秒,所以后所有的时钟运算的都没有用了。
Dim dat As Date
Dim t As Integer

Private Sub Form_Load()
Timer1.Interval = 100
dat = Time
t = 0

End Sub

Private Sub Timer1_Timer()
Label1 = Time

If Time = DateAdd("s", 3, dat) Then
dat = Time
t = t + 1
Label3.Caption = Str(t)
End If
Label2 = dat
End Sub

你自己试试是不是有用呢。

Option Explicit
Dim t As Integer

Private Sub Form_Load()
t = 0
Timer1.Interval = 2000
End Sub

Private Sub Timer1_Timer()
t = t + 1
Label1.Caption = Str(t)
End Sub

其实这样就可以实现你要的功能了啊

你为什么要设置Timer1.