'用 API 做长延时的 Timer, 时间间隔(毫秒)为 Long 型,可达 47 天。
'模块中代码
Dim lTimerId As Long
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Private Sub TimerProc(ByVal lHwnd As Long, ByVal lMsg As Long, ByVal lTimerId As Long, ByVal lTime As Long)
Dim lResult As Long
'lResult = StopTimer(lTimerId)
Call InsertYourProcessNameHere
'code to be executed after interval
End Sub
Public Sub StartTimer(lInterval As Long) 'convert interval to milliseconds prior to passing
lTimerId = SetTimer(0, 0, lInterval, AddressOf TimerProc)
End Sub
Public Function StopTimer(lTimerId As Long) As Long
'must pass the TimerId returned by SetTimer
StopTimer = KillTimer(0, lTimerId)
End Function
Private Sub Form_Load()
'1秒执行一次
SetTimer Me.hwnd, 0, 1000, AddressOf TimerProc
end sub
------------------模块中
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Dim Tel As Long'记录时间
'这里写 执行代码
Public Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
Private Sub Form_Load()
date1=now
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
dim dateTmp as date
dateTmp = now
If DateDiff("n", date1, dateTmp)=10 Then '每隔十分钟,如果小时"n"改为"h"
Call YourOtherSub
date1 = dateTmp
End If
End Sub