Creo un classe in cui definisco le definizioni esplicite
classe1.cls avrà al suo interno l'oggetto persona in cui definisco le sue proprietà che sono nome, cognome, età
codice:
option explicit
public nome as string
public cognome as string
public eta as integer
questo è l'oggetto, poi creo la collezzione..quindi altra classe(cls_C_persona)
codice:
Private mCol As Collection
Public Function Add(Optional sKey As String) As classe1
'create a new object
Dim objNewMember As classe1
Set objNewMember = New classe1
'set the properties passed into the method
If Len(sKey) = 0 Then
mCol.Add objNewMember
Else
mCol.Add objNewMember, sKey
End If
'return the object created
Set Add = objNewMember
Set objNewMember = Nothing
End Function
Public Property Get Item(vntIndexKey As Variant) As classe1
'used when referencing an element in the collection
'vntIndexKey contains either the Index or Key to the collection,
'this is why it is declared as a Variant
'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
Set Item = mCol(vntIndexKey)
End Property
Public Property Get Count() As Long
'used when retrieving the number of elements in the
'collection. Syntax: Debug.Print x.Count
Count = mCol.Count
End Property
Public Sub Remove(vntIndexKey As Variant)
'used when removing an element from the collection
'vntIndexKey contains either the Index or Key, which is why
'it is declared as a Variant
'Syntax: x.Remove(xyz)
mCol.Remove vntIndexKey
End Sub
Private Sub Class_Initialize()
'creates the collection when this class is created
Set mCol = New Collection
End Sub
Private Sub Class_Terminate()
'destroys collection when this class is terminated
Set mCol = Nothing
End Sub
ora l'oggetto e collezioni sono servite...sarà grezzo, magari nemmeno troppo perfetto per i guru di questo forum..ma almeno lo sforzo lo fatto.
Ciao a tutti