Inserting Items into a Vb6 collection [duplicate]

-2

Good morning, people. The circumstance is as follows. I created a Type and it has its attributes. I would like to know how do I insert data into a collection (in Vb6). For example: I created the Type Person that has a first and last name attribute, now I need to create a collection of this type.

    
asked by anonymous 23.04.2014 / 15:10

1 answer

2

A collection in VB6 / VBA is of type Colletion and accepts any object of reference, one way to do this is in the Module or in your Class to have a property that consumes your collection for that specific type.

For example:

Private Pessoas_ As New Colletion

Private Sub PopulaPessoas()
      Dim Pessoa1 As MeuTipoPessoa
      Dim Pessoa2 As MeuTipoPessoa
      Dim Pessoa3 As MeuTipoPessoa

      Pessoas_.Add(Pessoa1)
      Pessoas_.Add(Pessoa2)
      Pessoas_.Add(Pessoa3)
End Sub

Public Property Get Professores() As Colletion
    Dim oPessoa As MeuTipoPessoa
    Dim oColecaoRetorno As New Colletion

    For Each oPessoa In Pessoas_
        If (oPessoa.EhProfessor) Then
            oColecaoRetorno.Add(oPessoa)
        End If    
    Next
    Set Professores = oColecaoRetorno
End Property
    
23.04.2014 / 15:24