home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch15 / evntimer / timercls.cls < prev   
Encoding:
Visual Basic class definition  |  1998-07-06  |  1.6 KB  |  74 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "EventTimerClass"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Dim cFrm As Form1
  15. Dim WithEvents eTimer As Timer
  16. Attribute eTimer.VB_VarHelpID = -1
  17. Dim totalInterval As Double
  18. Dim T1 As Double
  19. Dim Counting As Boolean
  20.  
  21. Event Minute()
  22. Event Hour()
  23.  
  24. Public Sub StartCounting()
  25.     T1 = Time
  26.     Counting = True
  27. End Sub
  28.  
  29. Public Sub StopCounting()
  30.     totalInterval = totalInterval + Time - T1
  31.     Counting = False
  32. End Sub
  33.  
  34. Property Get ElapsedTime() As Double
  35.     ElapsedTime = totalInterval
  36. End Property
  37.  
  38. Public Sub ResetTimer()
  39.     totalInterval = 0
  40. End Sub
  41.  
  42. Private Sub Class_Initialize()
  43.     Set cFrm = New Form1
  44.     Load cFrm
  45.     Set eTimer = cFrm.Timer1
  46. End Sub
  47.  
  48. Private Sub eTimer_Timer()
  49. Static seconds As Long
  50. Static minutes As Long
  51. Static hours As Long
  52. Dim RaiseMinutes As Boolean, RaiseHours As Boolean
  53.  
  54.     If Not Counting Then Exit Sub
  55.     RaiseMinutes = False
  56.     RaiseHours = False
  57.     seconds = seconds + eTimer.Interval / 1000
  58.     If seconds = 60 Then
  59.         minutes = minutes + 1
  60.         seconds = 0
  61.         RaiseMinutes = True
  62.         If minutes = 60 Then
  63.             hours = hours + 1
  64.             minutes = 0
  65.             RaiseHours = True
  66.         End If
  67.     End If
  68.     If RaiseHours Then
  69.         RaiseEvent Hour
  70.     ElseIf RaiseMinutes Then
  71.         RaiseEvent Minute
  72.     End If
  73. End Sub
  74.