Reputation: 147
In visual basic 6.0 , I am working about array and listbox. I want that when I click the command button all the string values will be displayed in the listbox, thus I wanted to use objects from class and call this in the form. I would like to know how to call the string values for listbox from a class module to the form.
I already tried the string array but only for messagebox.I dont know how to use the listbox.I can show what I did. I created a method friendslist() using class1. As seen there I used messagebox I want to replace it with the text.Then Call those text it in command1_click() as the value for listbox
Dim friends(5) As String
friends(0) = "Anna"
friends(1) = "Mona"
friends(2) = "Marie"
friends(3) = "Kent"
friends(4) = "Jona"
friends(5) = "Fatima"
For a = 0 To 5
MsgBox "Your friends are: " & friends(a)
Next
End Sub
Private Sub Command1_Click()
Dim myfriends As New Class1
Call myfriends.friendslist
End Sub
This is my expected output
Upvotes: 0
Views: 536
Reputation: 720
You could pass a ListBox as a parameter to friendslist() method.
' insert this code into Class1
Public Sub FriendsList(oList As ListBox)
Dim a As Long
Dim friends(5) As String
friends(0) = "Anna"
friends(1) = "Mona"
friends(2) = "Marie"
friends(3) = "Kent"
friends(4) = "Jona"
friends(5) = "Fatima"
oList.Clear
For a = LBound(friends) To UBound(friends)
oList.AddItem friends(a)
Next a
End Sub
' insert this code into form
Private Sub Command1_Click()
Dim oFriends As Class1
Set oFriends = New Class1
oFriends.FriendsList List1 ' instead of List1, type the actual name of ListBox control
Set oFriends = Nothing
End Sub
Upvotes: 1