home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / ch_code / ch16 / axstats / stats.ctl < prev    next >
Encoding:
Text File  |  1998-07-08  |  3.5 KB  |  131 lines

  1. VERSION 5.00
  2. Begin VB.UserControl Stats 
  3.    ClientHeight    =   795
  4.    ClientLeft      =   0
  5.    ClientTop       =   0
  6.    ClientWidth     =   945
  7.    InvisibleAtRuntime=   -1  'True
  8.    ScaleHeight     =   795
  9.    ScaleWidth      =   945
  10.    Begin VB.Label Label1 
  11.       Alignment       =   2  'Center
  12.       BorderStyle     =   1  'Fixed Single
  13.       Caption         =   "AX Stats"
  14.       BeginProperty Font 
  15.          Name            =   "Verdana"
  16.          Size            =   12
  17.          Charset         =   0
  18.          Weight          =   700
  19.          Underline       =   0   'False
  20.          Italic          =   0   'False
  21.          Strikethrough   =   0   'False
  22.       EndProperty
  23.       Height          =   600
  24.       Left            =   0
  25.       TabIndex        =   0
  26.       Top             =   0
  27.       Width           =   700
  28.    End
  29. End
  30. Attribute VB_Name = "Stats"
  31. Attribute VB_GlobalNameSpace = False
  32. Attribute VB_Creatable = True
  33. Attribute VB_PredeclaredId = False
  34. Attribute VB_Exposed = True
  35. '  ******************************
  36. '  ******************************
  37. '  ** MASTERING VB6            **
  38. '  ** by Evangelos Petroutos   **
  39. '  ** SYBEX, 1998              **
  40. '  ******************************
  41. '  ******************************
  42. Dim DataCollection As New Collection
  43.  
  44. Public Function Item(index As Long) As Double
  45.     If index < 0 Or index > DataCollection.Count Then
  46.         Err.Raise vbObjectError + 1, "AXStats", "Index out of bounds (" & index & ")"
  47.     Else
  48.         Item = DataCollection(index)
  49.     End If
  50. End Function
  51.  
  52. Public Function Clear() As Boolean
  53. On Error GoTo ClearError
  54.     For i = DataCollection.Count To 1 Step -1
  55.         DataCollection.Remove i
  56.     Next
  57.     Clear = True
  58.     Exit Function
  59.     
  60. ClearError:
  61.     Clear = False
  62. End Function
  63.  
  64. Public Property Get Count() As Long
  65. Attribute Count.VB_MemberFlags = "400"
  66.     Count = DataCollection.Count
  67. End Property
  68.  
  69. Public Function Add(dValue As Double)
  70. On Error GoTo AddError
  71.     DataCollection.Add dValue
  72.     Add = True
  73.     Exit Function
  74. AddError:
  75.     Add = False
  76. End Function
  77.  
  78. Public Function Remove(index As Long) As Boolean
  79.     If (index) < 0 Or (index) > (DataCollection.Count) Then
  80.         Err.Raise vbObjectError + 2, "AXStats", "Invalid index specified (" & index & ")"
  81.         Remove = False
  82.     Else
  83.         DataCollection.Remove index
  84.         Remove = True
  85.     End If
  86. End Function
  87.  
  88. Public Property Get Average() As Double
  89. Attribute Average.VB_MemberFlags = "400"
  90. Dim dSum As Double
  91.     For Each Itm In DataCollection
  92.         dSum = dSum + Itm
  93.     Next
  94.     Average = dSum / DataCollection.Count
  95. End Property
  96.  
  97. Public Property Let Average(ByVal New_Average As Double)
  98.     If Ambient.UserMode = False Then Err.Raise 387
  99.     m_Average = New_Average
  100.     PropertyChanged "Average"
  101. End Property
  102.  
  103. Public Property Get Min() As Double
  104. Attribute Min.VB_MemberFlags = "400"
  105.     Min = 1E+202
  106.     For Each Itm In DataCollection
  107.         If Itm < Min Then Min = Itm
  108.     Next
  109. End Property
  110.  
  111. Public Property Get Max() As Double
  112. Attribute Max.VB_MemberFlags = "400"
  113.     Max = -1E+202
  114.     For Each Itm In DataCollection
  115.         If Itm > Max Then Max = Itm
  116.     Next
  117. End Property
  118.  
  119. Public Property Let Max(ByVal New_Max As Double)
  120.     If Ambient.UserMode = False Then Err.Raise 387
  121.     m_Max = New_Max
  122.     PropertyChanged "Max"
  123. End Property
  124.  
  125. Private Sub UserControl_Resize()
  126.     UserControl.Width = 800
  127.     UserControl.Height = 600
  128.     Label1.Width = UserControl.Width
  129.     Label1.Height = UserControl.Height
  130. End Sub
  131.