This is a CountDown Timer based on Woka's APITimer Class.
I needed to make this to suppress messages in a DCOM environment, but the suppression had to expire after some milliseconds.
VB Code:
Option Explicit ' ' <CountDownTimer.cls> ' ' Author: Dave Sell ' ' References: ' ' - vbAPITimerTools (vbAPITimer.dll) ' Public Event Refresh() Public Event Finsihed() Public Event Started() ' Private WithEvents m_Timer As APITimer ' Private m_CountDownInterval As Long Private m_ActiveIntervals As Long Private m_blnRunning As Boolean ' Private Sub Class_Initialize() Set m_Timer = New APITimer m_CountDownInterval = 0 m_ActiveIntervals = 0 m_blnRunning = False End Sub Public Property Let Interval(ByVal vNewValue As Variant) m_CountDownInterval = vNewValue End Property Public Property Get Interval() As Variant Interval = m_CountDownInterval End Property Private Sub IncrementCountDown(lngIntervals As Long) ' If Not m_blnRunning Then m_Timer.StartTimer m_CountDownInterval m_blnRunning = True RaiseEvent Started End If ' m_ActiveIntervals = m_ActiveIntervals + lngIntervals ' End Sub Public Sub Increment() IncrementCountDown 1 End Sub Public Sub MultiIncrement(lngIntervals As Long) IncrementCountDown lngIntervals End Sub Private Sub m_Timer_Refresh() ' If m_blnRunning = True Then m_ActiveIntervals = m_ActiveIntervals - 1 RaiseEvent Refresh End If ' If m_ActiveIntervals = 0 Then m_Timer.StopTimer RaiseEvent Refresh RaiseEvent Finsihed m_blnRunning = False End If ' ' End Sub Public Property Get ActiveIntervals() As Variant ActiveIntervals = m_ActiveIntervals End Property
Here is a sample Form consumer:
VB Code:
Option Explicit ' Private WithEvents m_Timer As CountDownTimer ' Private Sub cmdIncrement_Click() m_Timer.Increment Me.Caption = m_Timer.ActiveIntervals End Sub Private Sub cmdIncrement10_Click() m_Timer.MultiIncrement 10 End Sub Private Sub Form_Load() Set m_Timer = New CountDownTimer m_Timer.Interval = 1000 End Sub Private Sub m_Timer_Refresh() Me.Caption = m_Timer.ActiveIntervals End Sub


Reply With Quote