home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Visual Database / Visual BASIC 5.0 (Ent. Edition) / Vb5ent Extractor.EXE / VB / SAMPLES / PGUIDE / PROGWOB / PWOEMPLS.CLS < prev    next >
Encoding:
Visual Basic class definition  |  1996-11-26  |  3.1 KB  |  110 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Employees"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = False
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11. ' >> Best viewed in Full Module view. <<
  12. '
  13. ' Storage for debug ID number.
  14. Private mlngDebugID As Long
  15. Implements IDebug
  16.  
  17. ' Private collection that does all the
  18. '   work.
  19. Private colEmployees As New Collection
  20.  
  21. ' NewEnum method enables the use of For
  22. ' -------       Each with the Employees
  23. '   collection class.  For an
  24. '   explanation, see "Creating Your Own
  25. '   Collection Class: The House of Bricks"
  26. '   in Books Online.
  27. '
  28. ' For NewEnum to work properly, its
  29. '   procedure ID must be set to -4.  To see
  30. '   this, select Procedure Attributes
  31. '   from the Tools menu.  In the Name box,
  32. '   select Item, then click the Advanced
  33. '   button.  You can see that the Procedure
  34. '   ID has been set to -4.  ("Hide this
  35. '   member" is checked, also, so that the
  36. '   NewEnum method is hidden in the Object
  37. '   Browser.)
  38. Public Function NewEnum() As IUnknown
  39. Attribute NewEnum.VB_UserMemId = -4
  40. Attribute NewEnum.VB_MemberFlags = "40"
  41.     ' Delegate to the private Collection
  42.     '   object's _NewEnum method.
  43.     Set NewEnum = colEmployees.[_NewEnum]
  44. End Function
  45.  
  46. ' Add method creates a new Employee in
  47. ' ---       the collection.
  48. '
  49. Public Function Add(ByVal Name As String, _
  50.                 ByVal Salary As Double) As Employee
  51.     Dim empNew As New Employee
  52.     Static intEmpNum As Integer
  53.     ' Using With shortens property references (.ID instead of empNew.ID)
  54.     ' and speeds up execution.
  55.     With empNew
  56.         ' Generate a unique ID for the new employee.
  57.         intEmpNum = intEmpNum + 1
  58.         .ID = "E" & Format$(intEmpNum, "00000")
  59.         .Name = Name
  60.         .Salary = Salary
  61.         ' Add the Employee object reference to the collection, using its
  62.         ' ID property as the key.
  63.         colEmployees.Add empNew, .ID
  64.     End With
  65.     ' It is good practice to return a reference to the new member.
  66.     Set Add = empNew
  67. End Function
  68.  
  69. ' To see how the Item method was made the
  70. '   default method for the Employees
  71. '   collection, select Procedure Attributes
  72. '   from the Tools menu.  In the Name box,
  73. '   select Item, then click the Advanced
  74. '   button.  You can see that (Default)
  75. '   has been selected in the Procedure ID
  76. '   box.
  77. Public Function Item(ByVal Index As Variant) As Employee
  78.     Set Item = colEmployees.Item(Index)
  79. End Function
  80.  
  81. Public Function Count() As Long
  82.     Count = colEmployees.Count
  83. End Function
  84.  
  85. Public Sub Delete(ByVal Index As Variant)
  86.     colEmployees.Remove Index
  87. End Sub
  88.  
  89. Private Sub Class_Initialize()
  90.     mlngDebugID = DebugInit(Me)
  91. End Sub
  92.  
  93. Private Sub Class_Terminate()
  94.     DebugTerm Me
  95. End Sub
  96.  
  97. ' -------- IDebug Implementation --------
  98. '
  99. ' IDebug.DebugID gives you a way to tell
  100. ' ====== -------    objects apart.  It's
  101. '   required by the DebugInit, DebugTerm,
  102. '   and DebugShow debugging procedures
  103. '   declared in modFriend.
  104. '
  105. Private Property Get IDebug_DebugID() As Long
  106.     IDebug_DebugID = mlngDebugID
  107. End Property
  108.  
  109.  
  110.