Inserting Items in a Vb6 Collection

Asked

Viewed 1,111 times

-2

Good morning, you guys. The situation is as follows. I created a Type and it has its attributes. I would like to know how I do to insert data in a Collection (in Vb6). FOR EXAMPLE: I created Type Person q has name and surname attribute, now I need to create a collection of this type.

1 answer

2

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

Ex:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.