home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch15 / axstat / statclss.cls < prev    next >
Encoding:
Visual Basic class definition  |  1998-07-06  |  2.4 KB  |  97 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 = "AXStat"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. '  ******************************
  15. '  ******************************
  16. '  ** MASTERING VB6            **
  17. '  ** by Evangelos Petroutos   **
  18. '  ** SYBEX, 1998              **
  19. '  ******************************
  20. '  ******************************
  21. Dim DataCollection As New Collection
  22. Public Enum AXStatErrors
  23.     AddError = 1
  24.     RemoveError = 2
  25. End Enum
  26.  
  27. Public Function Item(index As Long) As Double
  28.     If index < 0 Or index > DataCollection.Count Then
  29.         Err.Raise vbObjectError + 1, "AXStats.StatClass", "Index out of bounds (" & index & ")"
  30.     Else
  31.         Item = DataCollection(index)
  32.     End If
  33. End Function
  34.  
  35. Public Function Clear() As Boolean
  36. Dim i As Long
  37. On Error GoTo ClearError
  38.     For i = DataCollection.Count To 1 Step -1
  39.         DataCollection.Remove i
  40.     Next
  41.     Clear = True
  42.     Exit Function
  43.     
  44. ClearError:
  45.     Clear = False
  46. End Function
  47.  
  48. Public Property Get Count() As Long
  49.     Count = DataCollection.Count
  50. End Property
  51.  
  52. Public Function Add(dValue As Double)
  53. On Error GoTo AddError
  54.     DataCollection.Add dValue
  55.     Add = True
  56.     Exit Function
  57. AddError:
  58.     Add = False
  59. End Function
  60.  
  61. Public Function Remove(index As Long) As Boolean
  62.     If (index) < 0 Or (index) > (DataCollection.Count) Then
  63.         Err.Raise 2 + vbObjectError, "AXStats.StatClass", "Invalid index specified (" & index & ")"
  64.         Remove = False
  65.     Else
  66.         DataCollection.Remove index
  67.         Remove = True
  68.     End If
  69. End Function
  70.  
  71. Public Property Get Average() As Double
  72. Dim dSum As Double
  73. Dim itm As Long
  74.  
  75.     For itm = 1 To DataCollection.Count
  76.         dSum = dSum + DataCollection(itm)
  77.     Next
  78.     Average = dSum / DataCollection.Count
  79. End Property
  80.  
  81. Public Property Get Min() As Double
  82. Dim itm As Long
  83.     Min = 1E+202
  84.     For itm = 1 To DataCollection.Count
  85.         If DataCollection(itm) < Min Then Min = DataCollection(itm)
  86.     Next
  87. End Property
  88.  
  89. Public Property Get Max() As Double
  90. Dim itm As Long
  91.     Max = -1E+202
  92.     For itm = 1 To DataCollection.Count
  93.         If DataCollection(itm) > Max Then Max = DataCollection(itm)
  94.     Next
  95. End Property
  96.  
  97.