Listbox .ListCount/.List Issue
Code:
Private Sub Form_Load()
With List1
.AddItem "test1"
.AddItem "test2"
.AddItem "test3"
.AddItem "test4"
.AddItem "test5"
End With
End Sub
Private Sub Command1_Click()
Dim i As Integer
For i = 0 To List1.ListCount 'tried i = 1 to ...
MsgBox List1.List(i)
Exit Sub
Next i
End Sub
It only returns the first string in the Listbox and not ALL the strings. I cannot figure this out.
Any suggestions?
Re: Listbox .ListCount/.List Issue
For i = 0 To List1.ListCount - 1
Re: Listbox .ListCount/.List Issue
..and remove the "Exit Sub" ;)
Re: Listbox .ListCount/.List Issue
Looks like you're exiting your sub after it meets the first condition. So you'll never get to I = 1 or beyond. Plus it needs to be to listcount -1.
Code:
For i = 0 To List1.ListCount 'tried i = 1 to ...
MsgBox List1.List(i)
Exit Sub
Next i
If you want to list all elements in a messagebox, you could copy all the elements to a string field and then display the msgbox when done.
Code:
Private Sub Command1_Click()
Dim i As Integer
dim stest as string
For i = 0 To List1.ListCount -1
stest = stest & list1(i) & vbcrlf
Next i
MsgBox stest
End Sub