Results 1 to 1 of 1

Thread: CountDownTimer

  1. #1

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    CountDownTimer

    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:
    1. Option Explicit
    2. '
    3. ' <CountDownTimer.cls>
    4. '
    5. ' Author: Dave Sell
    6. '
    7. ' References:
    8. '
    9. '   - vbAPITimerTools (vbAPITimer.dll)
    10. '
    11. Public Event Refresh()
    12. Public Event Finsihed()
    13. Public Event Started()
    14. '
    15. Private WithEvents m_Timer As APITimer
    16. '
    17. Private m_CountDownInterval As Long
    18. Private m_ActiveIntervals As Long
    19. Private m_blnRunning As Boolean
    20. '
    21.  
    22. Private Sub Class_Initialize()
    23.     Set m_Timer = New APITimer
    24.     m_CountDownInterval = 0
    25.     m_ActiveIntervals = 0
    26.     m_blnRunning = False
    27. End Sub
    28.  
    29. Public Property Let Interval(ByVal vNewValue As Variant)
    30.     m_CountDownInterval = vNewValue
    31. End Property
    32.  
    33. Public Property Get Interval() As Variant
    34.     Interval = m_CountDownInterval
    35. End Property
    36.  
    37. Private Sub IncrementCountDown(lngIntervals As Long)
    38.     '
    39.     If Not m_blnRunning Then
    40.         m_Timer.StartTimer m_CountDownInterval
    41.         m_blnRunning = True
    42.         RaiseEvent Started
    43.     End If
    44.     '
    45.     m_ActiveIntervals = m_ActiveIntervals + lngIntervals
    46.     '
    47. End Sub
    48.  
    49. Public Sub Increment()
    50.     IncrementCountDown 1
    51. End Sub
    52.  
    53. Public Sub MultiIncrement(lngIntervals As Long)
    54.     IncrementCountDown lngIntervals
    55. End Sub
    56.  
    57. Private Sub m_Timer_Refresh()
    58.     '
    59.     If m_blnRunning = True Then
    60.         m_ActiveIntervals = m_ActiveIntervals - 1
    61.         RaiseEvent Refresh
    62.     End If
    63.     '
    64.     If m_ActiveIntervals = 0 Then
    65.         m_Timer.StopTimer
    66.         RaiseEvent Refresh
    67.         RaiseEvent Finsihed
    68.         m_blnRunning = False
    69.     End If
    70.     '
    71.     '
    72. End Sub
    73.  
    74. Public Property Get ActiveIntervals() As Variant
    75.     ActiveIntervals = m_ActiveIntervals
    76. End Property

    Here is a sample Form consumer:
    VB Code:
    1. Option Explicit
    2. '
    3. Private WithEvents m_Timer As CountDownTimer
    4. '
    5.  
    6. Private Sub cmdIncrement_Click()
    7.     m_Timer.Increment
    8.     Me.Caption = m_Timer.ActiveIntervals
    9. End Sub
    10.  
    11. Private Sub cmdIncrement10_Click()
    12.     m_Timer.MultiIncrement 10
    13. End Sub
    14.  
    15. Private Sub Form_Load()
    16.     Set m_Timer = New CountDownTimer
    17.     m_Timer.Interval = 1000
    18. End Sub
    19.  
    20. Private Sub m_Timer_Refresh()
    21.     Me.Caption = m_Timer.ActiveIntervals
    22. End Sub
    Last edited by Dave Sell; Apr 23rd, 2005 at 03:26 PM.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width