Question Trying to match a list item to an array

Old Marcus

Member
Joined
Sep 22, 2009
Messages
6
Programming Experience
Beginner
Hey guys, I'm having trouble trying to match a selected list item to a space in an array.

I'm trying to get the program to loop through the array and each time check if the contents of the array space match the selected list item, but I get errors when I try. I know I have the code wrong but I don't know how to fix it. Hoping someone here can help. :)

VB.NET:
Private Sub lstMembers_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstMembers.SelectedValueChanged
        Dim index As Integer = 0

        For iCount As Integer = 0 To arrMembers.GetUpperBound(0)
            If Not Str(arrMembers(index)).Contains(lstMembers.SelectedItem) Then
                index += 1
                MemberNumber += 1
            Else
                Exit For
            End If
        Next
    End Sub
 
Just to confirm, you're just trying to find the index in an array that matches the SelectedItem of a ListBox, right? If so, it's just one line of code:
VB.NET:
Dim index As Integer = Array.IndexOf(arrMembers, lstMembers.Text)
 
Back
Top