Dim nTimeM As LongPrivate Sub Form_Load() nTimeM = 0 Timer1.Interval = 1000 Timer1.Enabled = True End SubPrivate Sub Timer1_Timer() nTimeM = nTimeM + 1 If nTimeM >= 60*60 Then '每隔一小时 Call YourOtherSub nTimeM =0 End If End Sub
Dim date1 As datePrivate Sub Form_Load() date1=now Timer1.Interval = 1000 Timer1.Enabled = True End SubPrivate 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
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)
If Tel = 30 Then'30秒执行一次,可以改这个数字到任何大小,long类型
Tel = 0 End If Tel = Tel + 1
End Sub
Private Sub Form_Unload(Cancel As Integer) KillTimer Me.hwnd, 0 ' 卸载所时钟End Sub
'用 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 LongPrivate Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As LongPrivate 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 SubPublic Sub StartTimer(lInterval As Long) 'convert interval to milliseconds prior to passing lTimerId = SetTimer(0, 0, lInterval, AddressOf TimerProc) End SubPublic Function StopTimer(lTimerId As Long) As Long 'must pass the TimerId returned by SetTimer StopTimer = KillTimer(0, lTimerId) End Function'调用方式 Call StartTimer(5000) '5 seconds
最简单的,用timeGetTime eg:dim time as long do time=timeGetTime DoEvents Loop While timeGetTime-time < 具体间隔时间 下面为你要实现的功能代码......
nTimeM = 0
Timer1.Interval = 1000
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
nTimeM = nTimeM + 1
If nTimeM >= 60*60 Then '每隔一小时
Call YourOtherSub
nTimeM =0
End If
End Sub
date1=now
Timer1.Interval = 1000
Timer1.Enabled = True
End SubPrivate 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
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)
If Tel = 30 Then'30秒执行一次,可以改这个数字到任何大小,long类型
Tel = 0
End If
Tel = Tel + 1
End Sub
KillTimer Me.hwnd, 0
' 卸载所时钟End Sub
'模块中代码
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 LongPrivate Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As LongPrivate 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 SubPublic Sub StartTimer(lInterval As Long) 'convert interval to milliseconds prior to passing
lTimerId = SetTimer(0, 0, lInterval, AddressOf TimerProc)
End SubPublic Function StopTimer(lTimerId As Long) As Long
'must pass the TimerId returned by SetTimer
StopTimer = KillTimer(0, lTimerId)
End Function'调用方式
Call StartTimer(5000) '5 seconds
eg:dim time as long
do
time=timeGetTime
DoEvents
Loop While timeGetTime-time < 具体间隔时间
下面为你要实现的功能代码......