新建一个标准工程,将下面的代码拷贝到代码区Option ExplicitDim intTimerCount As IntegerPrivate Sub Form_Load() Timer1.Interval = 1000 '定时一秒 Timer1.Enabled = True intTimerCount = 5 '5秒后提示消息,这个值改成3600就是一个小时了 End SubPrivate Sub Timer1_Timer() Static intSelfCount As Integer intSelfCount = intSelfCount + 1 If intSelfCount = intTimerCount Then MsgBox intTimerCount & "秒" intSelfCount = 0 End If End Sub
API gettickcount()private sub timer1_timer () static tcount as long if tcount=0 then tcount=gettickcount() else if gettickcount-tcount=3600000 then ---------处理事件 tcount=0 endif end if
我举一个简单的例子,不知道对你是否有用……function nexttime(Tc as integer) as date Dim hTemp As Integer, mTemp As Integer,timeTemp hTemp = Tc / 60 mTemp = Tc Mod 60 timeTemp = TimeValue(CStr(hTemp) & ":" & CStr(mTemp) & ":00") NextTime = firstTime + timeTemp end fucction Private Sub Timer1_Timer() If nexttime(60)>now Then MsgBox "执行你需要的动作……" End If End Sub
Timer1.Interval = 1000 '定时一秒
Timer1.Enabled = True
intTimerCount = 5 '5秒后提示消息,这个值改成3600就是一个小时了
End SubPrivate Sub Timer1_Timer()
Static intSelfCount As Integer
intSelfCount = intSelfCount + 1
If intSelfCount = intTimerCount Then
MsgBox intTimerCount & "秒"
intSelfCount = 0
End If
End Sub
在Timer加上比较代码DateDiff("s", tim_now, Now) = 1000 * 60
gettickcount()private sub timer1_timer ()
static tcount as long
if tcount=0 then
tcount=gettickcount()
else
if gettickcount-tcount=3600000 then
---------处理事件
tcount=0
endif
end if
end sub
也没必要设成1000吧(当然楼上的一些只是举例)可以设60000这样每分钟一次,如果不要执行其它代码就这样比较好喽.
我举一个简单的例子,不知道对你是否有用……function nexttime(Tc as integer) as date
Dim hTemp As Integer, mTemp As Integer,timeTemp
hTemp = Tc / 60
mTemp = Tc Mod 60
timeTemp = TimeValue(CStr(hTemp) & ":" & CStr(mTemp) & ":00")
NextTime = firstTime + timeTemp
end fucction
Private Sub Timer1_Timer()
If nexttime(60)>now Then
MsgBox "执行你需要的动作……" End If
End Sub
其实利用静态变量很容易实现的