VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "AXStat"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
'  ******************************
'  ******************************
'  ** MASTERING VB6            **
'  ** by Evangelos Petroutos   **
'  ** SYBEX, 1998              **
'  ******************************
'  ******************************
Dim DataCollection As New Collection
Public Enum AXStatErrors
    AddError = 1
    RemoveError = 2
End Enum

Public Function Item(index As Long) As Double
    If index < 0 Or index > DataCollection.Count Then
        Err.Raise vbObjectError + 1, "AXStats.StatClass", "Index out of bounds (" & index & ")"
    Else
        Item = DataCollection(index)
    End If
End Function

Public Function Clear() As Boolean
Dim i As Long
On Error GoTo ClearError
    For i = DataCollection.Count To 1 Step -1
        DataCollection.Remove i
    Next
    Clear = True
    Exit Function
    
ClearError:
    Clear = False
End Function

Public Property Get Count() As Long
    Count = DataCollection.Count
End Property

Public Function Add(dValue As Double)
On Error GoTo AddError
    DataCollection.Add dValue
    Add = True
    Exit Function
AddError:
    Add = False
End Function

Public Function Remove(index As Long) As Boolean
    If (index) < 0 Or (index) > (DataCollection.Count) Then
        Err.Raise 2 + vbObjectError, "AXStats.StatClass", "Invalid index specified (" & index & ")"
        Remove = False
    Else
        DataCollection.Remove index
        Remove = True
    End If
End Function

Public Property Get Average() As Double
Dim dSum As Double
Dim itm As Long

    For itm = 1 To DataCollection.Count
        dSum = dSum + DataCollection(itm)
    Next
    Average = dSum / DataCollection.Count
End Property

Public Property Get Min() As Double
Dim itm As Long
    Min = 1E+202
    For itm = 1 To DataCollection.Count
        If DataCollection(itm) < Min Then Min = DataCollection(itm)
    Next
End Property

Public Property Get Max() As Double
Dim itm As Long
    Max = -1E+202
    For itm = 1 To DataCollection.Count
        If DataCollection(itm) > Max Then Max = DataCollection(itm)
    Next
End Property

