当我们单击对象时,如何将对象存储在vba ListBox中并检索它们?

时间:2019-06-19 14:08:30

标签: vba oop object listbox

我制作了一个方法,该方法采用表示人的arrayOReservists对象的全局数组,并将其对象显示在ListBox中。

        ' Fill the ListBox results with the names and surnames of the staff
        ListBoxResults.AddItem (arrayOReservists(i).Surname & " " & arrayOReservists(i).Name)
        ' we resize the table
        i = i + 1

当我双击ListBox中的一行时,另一种方法ListBoxResults_DblClick响应。它显示了一个用户窗体,我要将单击的对象发送到该用户窗体。但是,我不知道如何访问该对象。我的印象是,通过AddItem传输到ListBox的数据被转换为文本。

Private Sub ListBoxResults_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    Dim Msg As String
    Dim i As Integer
    Dim newInstanceOfMe As Object

    ' We look for the name and surname of the reserviser we clicked on.
    For i = 0 To ListBoxResults.ListCount - 1
        If ListBoxResults.Selected(i) Then
            ReservistName = ListBoxResults.List(i)
        End If
    Next i

    ' Consider the case in which you click on the TextBox Results while it is empty
    If False Then
        If ReservistName <> "" Then
            Set newInstanceOfMe = UserForms.Add(Me.Name)          
            newInstanceOfMe.Caption = ReservistName
            newInstanceOfMe.Show
            Unload newInstanceOfMe
            Set newInstanceOfMe = Nothing
        End If
    End If
    ' Pass the name, first name to ReservistUserForm and in the Load that filters the list of these fields by obtaining the oReservist object.
    ' Once you have the information of that user, the following will be to map the information to the corresponding textBox.
    ReservistFormUserForm.Caption = ReservistName
    ReservistFormUserForm.Show

End Sub

实际上,当我显示MsgBox (ListBoxResults.List (i))时,我只有名字和姓氏,而没有对象。

因此,如何将对象存储在vba ListBox中并在单击它们时检索它们?例如,这将允许我将其放置在我可以访问的全局变量中在用户窗体中。

0 个答案:

没有答案