Click to See Complete Forum and Search --> : A Collection of user define type


September 21st, 1999, 04:41 PM
How to write a user define type of Collection? The following code won't work.
Type EmployeeRecord
ID As Integer
Name As String
Address As String
End Type

Sub CreateRecord()
Dim MyRecord As EmployeeRecord
Dim MyCollection As Collection

MyRecord.ID = 12003 ' Assign a value to an element.
Set MyCollection = new Collection
MyCollection.Add(MyRecord)
End Sub

Ravi Kiran
September 22nd, 1999, 12:37 AM
Collections Work only on objects. So turn your employee type into a class and it will work.
Some thing like this:
Add a Class, and name it CEmployeeRecord
in it put these members. Make them all Public

public ID as Integer
public Name as string
public Address as string



and biuld your collection like this:

Sub CreateRecord()
Dim MyRecord as CEmployeeRecord
Dim MyCollection as Collection

set MyRecord = new CEmployeeRecord
MyRecord.ID = 12003 ' Assign a value to an element.
set MyCollection = new Collection
MyCollection.Add(MyRecord)
set MyRecord = nothing
End Sub





RK