home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch20 / statclss / axstats.cls next >
Encoding:
Visual Basic class definition  |  1996-05-13  |  2.1 KB  |  88 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 = "AXStats"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Dim DataCollection As New Collection
  15.  
  16. Public Function Item(index)
  17.     If index < 0 Or index > DataCollection.Count Then
  18.         Err.Raise vbError + 1, "StatClass", "Index out of bounds (" & index & ")"
  19.     Else
  20.         Item = DataCollection(index)
  21.     End If
  22. End Function
  23.  
  24. Public Function Clear()
  25. On Error GoTo ClearError
  26.     For i = DataCollection.Count To 1 Step -1
  27.         DataCollection.Remove i
  28.     Next
  29.     Clear = True
  30.     Exit Function
  31.     
  32. ClearError:
  33.     Clear = False
  34. End Function
  35.  
  36. Public Property Get Count()
  37.     Count = DataCollection.Count
  38. End Property
  39.  
  40. Public Function Add(dValue)
  41. On Error GoTo AddError
  42.     DataCollection.Add dValue
  43.     Add = True
  44.     Exit Function
  45. AddError:
  46.     Add = False
  47. End Function
  48.  
  49. Public Function Remove(index)
  50.     If (index) < 0 Or (index) > (DataCollection.Count) Then
  51.         Err.Raise vbError + 2, "StatClass", "Invalid index specified (" & index & ")"
  52.         Remove = False
  53.     Else
  54.         DataCollection.Remove index
  55.         Remove = True
  56.     End If
  57. End Function
  58.  
  59. Public Property Get Average()
  60. Dim dSum As Double
  61.     For Each Itm In DataCollection
  62.         dSum = dSum + Itm
  63.     Next
  64.     Average = dSum / DataCollection.Count
  65. End Property
  66.  
  67. Public Property Get Min()
  68.     Min = DataCollection(1)
  69.     For Each Itm In DataCollection
  70.         If Itm < Min Then Min = Itm
  71.     Next
  72. End Property
  73.  
  74. Public Property Get Max()
  75.     Max = DataCollection(1)
  76.     For Each Itm In DataCollection
  77.         If Itm > Max Then Max = Itm
  78.     Next
  79. End Property
  80.  
  81. Private Sub UserControl_Resize()
  82.     UserControl.Width = 800
  83.     UserControl.Height = 600
  84.     Label1.Width = UserControl.Width
  85.     Label1.Height = UserControl.Height
  86. End Sub
  87.  
  88.