Article ID: 161215
Article Last Modified on 11/23/2006
Public EmployeeName As String
You typically use a public variable in a class modules to define
properties for the class.
Sub MyCollection()
Dim employees As New Collection 'Create the collection object.
Dim num As Integer
num = 0 'Counter for number of employees added to the
'collection.
Do
Dim employee As New EmpClass 'Create new instance of the
'EmpClass class.
num = num + 1
newname = InputBox("Enter new employee name" & Chr(13) _
& "or press Cancel to see list of employees.")
If newname <> "" Then 'You did not press Cancel.
employee.EmployeeName = newname
employees.Add Item:=employee, key:=CStr(num)
Set employee = Nothing 'Clear the current reference
'in preparation for next one.
End If
Loop Until newname = "" 'You pressed Cancel.
For Each x In employees
MsgBox x.EmployeeName 'Display the employee name.
Next
MsgBox employees.Count 'Current number of employees in
collection.
For Each x In employees
employees.Remove 1 'Remove each employee from the
collection.
Next
MsgBox employees.Count 'Display a count of zero because
'all employees were removed from the
'collection.
End Subadd method
collections, described
Additional query words: 97 for Windows XL97
Keywords: kbdtacode kbprogramming KB161215