-
Hi!
I'm looking for a good example of using a collection in a class. But the collection has to be an alternative for an array of an User Defined Type.. Get It?
My Problem:
I Have a type, Let's say CustomerType and a collection in my class "clsCustomers":
Dim CustColl As Collection
Type CustomerType
Name as String
Address as String
Email as String
etc...
End Type
And a subroutine in my class:
Public Sub AddCustomer(Itm as customertype)
CustColl.Add Itm
End Sub
In my form I have the code:
Dim F As New clsCustomers
F.AddCustomer TheCustomer
When Compiling I get the error "Cannot define a public user-defined type within a private object module"
When I move the type to a public module I get: "Only Public User Defined Types defined in public object modules can be used as parameters or returntypes for public procedures of class modules or as fields of public userdefined types"
I read the errormessages a thousand times, but can't seem to understand what they're saying.. Any help?
-
Sorry to be the one to have to tell you, but VB does not like UDT’s and collections.
The solution is to make the UDT a class in itself. You can then have a collection of a class with no worries.
So you will have a customer Class (object), and then you will have a collection of these objects. You can do all this with the Class builder utility. It is an Add In for VB that you should be able to access through the Add In Manager.