I've programmed in several languages but i'm at my first tests on VBA.
I need to make a class who has as a property, an array of objects of another class. Let's make an example a Person class who keeps info about name, surname and addresses. And an address class who keeps info about a street and zipcode. A person could have many addresses so Person should have an arrays of Addresses.
class Address
Private pStreet as String
Private pZip as Int
Public Property Let Street(val As String)
pStreet = val
End Property
Public Property Get Street() As String
Street = pStreet
End Property
Public Property Let Zip(val As String)
pZip = val
End Property
Public Property Get Zip() As String
Zip = pZip
End Property
class Person
Private pName as String
Private pSurname as String
Private pAddresses() as Address
Public Property Let Name(val As String)
pName = val
End Property
Public Property Get Name() As String
Name = pName
End Property
Public Property Let Surname(val As String)
pSurname = val
End Property
Public Property Get Surname() As String
Surame = pSurname
End Property
How should i manage the array of Address?
i tried with such code but if i try to call this method on a person object i get an error" obect doesn't support this property or method"
Public Sub addAddress(val as Address)
ReDim pAddresses(1)
pAddresses(0) = val
End Sub
what's the way to do this? i cannot find any tutorial or something who shows how to use arrays of objects inside of an object
Set pAddresses(0) = val.