Option Explicit Dim strEndTime As String Private Sub Form_Load() tmrP.Interval = 300 '间隔300毫秒执行一次Timer事件 strEndTime = "2011-6-9 0:0:0" '给截至时间赋值 Text1.Text = "" End Sub '求的是距离 2011年06月09日0时0分0秒 的倒计时 Private Sub tmrP_Timer() Dim lngP As Long Dim strDay As String '剩余时间:日 Dim strHour As String '剩余时间:时 Dim strMin As String '剩余时间:分 Dim strSecond As String '剩余时间:秒
strSecond = lngP Mod 60 '计算秒 strMin = (lngP \ 60) Mod 60 '计算分 strHour = (lngP \ 3600) Mod 24 '计算时 strDay = (lngP \ 3600) \ 24 '计算日
'显示剩余时间 Text1.Text = strDay & "天" & strHour & "时" & strMin & "分" & strSecond & "秒" End Sub
“timer控件计时不太精确”?为什么这样说呢?倒计时其实很简单,看看下面的示例,从100倒数到1:'首先放入一个timer1控件 '再放入一个Label1控件,她的Caption属性设为100 '他们的名称属性保持不变 'Timer1的Interval属性设为1000,就是每一秒(=1000毫秒)发生一次Timer事件 Const A As Integer = 100Private Sub Timer1_Timer()'timer控件的timer事件 Static B As Integer'声明静态变量 B = B + 1 If Label1.Caption > 0 Then Label1.Caption = 100 - B Else Timer1.Enabled = False End if End Sub效果不错,不知道你是不是没设置Timer1的Interval属性,自己检查一下吧!!
Option Explicit
Dim strEndTime As String
Private Sub Form_Load()
tmrP.Interval = 300 '间隔300毫秒执行一次Timer事件
strEndTime = "2011-6-9 0:0:0" '给截至时间赋值
Text1.Text = ""
End Sub
'求的是距离 2011年06月09日0时0分0秒 的倒计时
Private Sub tmrP_Timer()
Dim lngP As Long
Dim strDay As String '剩余时间:日
Dim strHour As String '剩余时间:时
Dim strMin As String '剩余时间:分
Dim strSecond As String '剩余时间:秒
lngP = DateDiff("s", Now, strEndTime) '取得剩余的总时间,单位:秒
strSecond = lngP Mod 60 '计算秒
strMin = (lngP \ 60) Mod 60 '计算分
strHour = (lngP \ 3600) Mod 24 '计算时
strDay = (lngP \ 3600) \ 24 '计算日
'显示剩余时间
Text1.Text = strDay & "天" & strHour & "时" & strMin & "分" & strSecond & "秒"
End Sub
'再放入一个Label1控件,她的Caption属性设为100
'他们的名称属性保持不变
'Timer1的Interval属性设为1000,就是每一秒(=1000毫秒)发生一次Timer事件
Const A As Integer = 100Private Sub Timer1_Timer()'timer控件的timer事件
Static B As Integer'声明静态变量
B = B + 1
If Label1.Caption > 0 Then
Label1.Caption = 100 - B
Else
Timer1.Enabled = False
End if
End Sub效果不错,不知道你是不是没设置Timer1的Interval属性,自己检查一下吧!!
我再另想方法吧,不过分还是给二位了,一家一半,呵呵,