Reliable, no-crash timer for VBA. Code can be debugged and stopped safely.
Windows
notes:
SetTimer
is used for calling back VBA code at regular intervals- VBA does all the heavy lifting
- memory allocation - no need for side-allocations
- break mode check - so that timer calls are ignored / skipped in break / debug mode
- timer cleanup - timer is removed when the corresponding form is destroyed
Mac
notes:
- not implemented, yet
Download the latest release.
Just import the following code modules in your VBA Project:
SafeTimer.cls
LibTimers.bas
TimerForm.frm
- Alternatively, this can be easily recreated from scratch in 2 easy steps:- insert new form
- rename it to
TimerForm
Just add a SafeTimer
instance WithEvents
to any of your classes. The TimerCall
event will be raised at the desired interval. See demo.
Optionally, you can pass a Variant
when you call SafeTimer.StartTimer
so that it is passed back in the event.
Windows:
- each instance of
SafeTimer
class callsSetTimer
when itsStartTimer
method is called - each callback call (at set interval) to
SafeTimer.TimerProc
will raise aTimerCall
event to any listening classes - a single call to
VariantCopy
is made so that we can copy memory (no kernel.dll needed) - a few assmebly bytes (just 23 on x64 and just 20 on x32) are used to redirect the timer call to the correct
SafeTimer
instance
Mac
:
- not implemented
Import the following code modules:
Demo.bas
- runDemoMain
DemoTimer.cls
There is also a Demo Workbook available for download.