-
Does anyone know how I can get my program to perform an action every 30 minutes. This amount is too big for a timer. I have tried putting it into a loop checking to see if the oldtime + 30 mins equals new time, but it stops responding properly
Thanks a lot
Mark
-
You can use a timer. You will also need a variable.
Code:
Timer1.Interval = ?? 'whatever you chose.
Private Sub Timer1_Timer()
Static iTime As long
iTime = iTime + Timer1.Interval
If iTime >= 1800000 Then '30 minutes
'do something.
iTime = 0
End If
End Sub
-
Thanks. Why didn't I think of that myself?
-
SetTimer API
I think this is better, because it does not need any OCX control.
Code:
Option Explicit
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
Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
MsgBox "30 minutes is over."
End Sub
Private Sub Form_Load()
SetTimer Form1.hwnd, 0, 1800000, AddressOf TimerProc
End Sub
Private Sub Form_Unload()
KillTimer Form1.hwnd, 0
End Sub