Option Explicit
'1 Crearemos el timer o timers que necesitemos instanciando esta clase sin depender del formulario.
'Ej: Public WithEvents oTimer1 As clsTimer
'2 Para definir las acciones a realizar en el evento OnTimer, en el formulario, debemos crear un 'procedimento que se llamará: Nombre del objeto timer que hallamos creado + "_OnTimer".
'Ejemplo objeto oTimer1 -> Private Sub oTimer1_OnTimer() ..... End Sub
'3 Iniciar timer: oTimer1.Startit
'4 Parar timer: oTimer1.Stopit
'3 Iniciar timer: oTimer1.Startit
'4 Parar timer: oTimer1.Stopit
Option Compare Database
Option Explicit
'Windows API Function Declarations
#If Win64 = 1 Then
Private Declare PtrSafe Function SetTimer Lib "user32" ( _
ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr, _
ByVal uElapse As LongLong, ByVal lpTimerFunc As LongPtr) As LongLong
Private Declare PtrSafe Function KillTimer Lib "user32" ( _
ByVal hwnd As LongPtr, ByVal nIDEvent As LongPtr) As LongLong
#Else
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
#End If
#If Win64 = 1 Then
Private TimerID As LongLong
#Else
Private TimerID As Long
#End If
Public Event OnTimer()
'Start timer
Public Sub Startit(IntervalMs As Long)
TimerID = SetTimer(Application.hWndAccessApp, ObjPtr(Me), IntervalMs, AddressOf Timers.TimerProc)
End Sub
'Stop timer
Public Sub Stopit()
If TimerID <> -1 Then
KillTimer Application.hWndAccessApp, TimerID
TimerID = 0
End If
End Sub
'Trigger Public event
Public Sub RaiseTimerEvent()
RaiseEvent OnTimer
End Sub
No hay comentarios:
Publicar un comentario