Guest User

Untitled

a guest
Mar 20th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. Public Sub AddToTeam(emp As Employee)
  2.  
  3. Dim cnt As Long
  4. cnt = UBound(pTeam)
  5.  
  6. If Not pTeam(0) Is Nothing Then
  7. ReDim Preserve pTeam(cnt + 1)
  8. cnt = cnt + 1
  9. End If
  10. Set pTeam(cnt) = emp
  11.  
  12. End Sub
  13.  
  14. Private Sub Class_Initialize()
  15. ReDim pTeam(0)
  16. End Sub
  17.  
  18. Option Explicit
  19.  
  20. Public Sub TestMe()
  21.  
  22. Dim EmpA As New Employee
  23. Dim EmpB As New Employee
  24. Dim ManA As New Employee
  25. Dim TeamA As New Team
  26.  
  27. ManA.Name = "John Doe Top Manager"
  28. EmpA.Name = "Peter"
  29. EmpB.Name = "George"
  30.  
  31. Set EmpB.Manager = ManA
  32. TeamA.Name = "The best team!"
  33.  
  34. TeamA.AddToTeam ManA
  35. TeamA.AddToTeam EmpA
  36. TeamA.AddToTeam EmpB
  37.  
  38. TeamA.PrintNames
  39. Debug.Print TeamA.Name
  40. TeamA.PrintInfoForManagers
  41.  
  42. End Sub
  43.  
  44. Option Explicit
  45.  
  46. Private pName As String
  47. Private pManager As Employee
  48. Private pAge As Long
  49. Private pTeam As String
  50. Private pHasManager As Boolean
  51.  
  52. Public Property Get HasManager() As Boolean
  53. HasManager = pHasManager
  54. End Property
  55.  
  56. Public Property Let HasManager(Value As Boolean)
  57. pHasManager = Value
  58. End Property
  59.  
  60. Public Property Get Manager() As Employee
  61. Set Manager = pManager
  62. End Property
  63.  
  64. Public Property Set Manager(Value As Employee)
  65. Set pManager = Value
  66. HasManager = True
  67. End Property
  68.  
  69. Public Property Get Name() As String
  70. Name = pName
  71. End Property
  72.  
  73. Public Property Let Name(Value As String)
  74. pName = Value
  75. End Property
  76.  
  77. Public Property Get Team() As Employee
  78. Team = pTeam
  79. End Property
  80.  
  81. Public Property Let Team(Value As Employee)
  82. pTeam = Value
  83. End Property
  84.  
  85. Option Explicit
  86.  
  87. Private pTeam() As Employee
  88. Private pName As String
  89.  
  90. Public Sub PrintInfoForManagers()
  91.  
  92. Dim emp As Variant
  93. For Each emp In pTeam
  94. If emp.HasManager Then
  95. Debug.Print emp.Name & " is managed by " & emp.Manager.Name
  96. Else
  97. Debug.Print emp.Name & " has no manager."
  98. End If
  99. Next emp
  100.  
  101. End Sub
  102.  
  103. Public Sub PrintNames()
  104.  
  105. Dim emp As Variant
  106. For Each emp In pTeam
  107. Debug.Print emp.Name
  108. Next emp
  109.  
  110. End Sub
  111.  
  112. Public Property Get Name() As String
  113. Name = pName
  114. End Property
  115.  
  116. Public Property Let Name(Value As String)
  117. pName = Value
  118. End Property
  119.  
  120. Public Sub AddToTeam(emp As Employee)
  121.  
  122. Dim cnt As Long
  123. cnt = UBound(pTeam)
  124.  
  125. If Not pTeam(0) Is Nothing Then
  126. ReDim Preserve pTeam(cnt + 1)
  127. cnt = cnt + 1
  128. End If
  129. Set pTeam(cnt) = emp
  130.  
  131. End Sub
  132.  
  133. Private Sub Class_Initialize()
  134. ReDim pTeam(0)
  135. End Sub
Add Comment
Please, Sign In to add comment