Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27156

Parallel Arrays: For loop error

$
0
0
Hi,

This application is an assignment that requires for me to list the names of kids into 2 list boxes from the (strChild)array. The second array(rdoList) consists of if the child is acceptable to participate in the sled race. So 2 arrays, one has the child's full name, second has the yes or no value of participation. The error I am getting is when I'm trying to display the elements in the (strChild) array that are parallel to the "Yes" value in the (rdoList) array into the list box and I get a "Conversion from string "Y" to type 'Integer' is not valid"

I highlighted the line RED which gives me the error.

Code:

Public Class Main
    'Declaring arrays
    Dim strChild(-1) As String ' holds the variables of the child's full name
    Dim rdoList(-1) As String  ' holds the Yes or No radio button selection

    Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
        Dim count As Integer = 0

        'Validation
        If txtFName.Text = "" Or txtLName.Text = "" Then
            MessageBox.Show("Please enter a First and Last Name")
        Else
            'Stores the name into the array
            ReDim Preserve strChild(strChild.Length)
            strChild(strChild.Length - 1) = txtLName.Text & "," & txtFName.Text

            'Stores the value of the radio button into the array
            If rdoYes.Checked Then
                ReDim Preserve rdoList(rdoList.Length)
                rdoList(rdoList.Length - 1) = "Y"
            Else
                ReDim Preserve rdoList(rdoList.Length)
                rdoList(rdoList.Length - 1) = "N"
            End If

          For i As Integer = 0 To rdoList(rdoList.Length - 1)
                If rdoList(i) = "Y" Then
                    Do Until 0 = strChild(strChild.Length - 1)
                        lstAllowed.Items.Add(strChild(i))
                    Loop
                End If
            Next
        End If

        'Clears out text boxes
        txtFName.Clear()
        txtLName.Clear()
        txtFName.Focus()
    End Sub

    Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
      'Closes the form
        Me.Close()
    End Sub
End Class


Viewing all articles
Browse latest Browse all 27156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>