title: How to search array and display in Text Box?
body: <p>I'm trying to figure out how I can search my array and then have the entry I'm looking for displayed in the original textbox.</p>
  
  <pre><code>        If idTextBox.Text = String.Empty Or nameTextBox.Text = String.Empty Then
          MessageBox.Show("Please enter a valid name and/or ID number.")
      Else
          'retrieve user input &amp; add to array
          studentArray(0, columnId) = idTextBox.Text
          studentArray(1, columnId) = nameTextBox.Text
          studentArray(2, columnId) = majorComboBox.Text
          studentArray(3, columnId) = yearComboBox.Text
          If honorsRadioButton.Checked = True Then
              studentArray(4, columnId) = "1"
          ElseIf notHonorsRadioButton.Checked = True Then
              studentArray(4, columnId) = "0"
          End If
  </code></pre>
  
  <p>This is the search and display code I have, it crashes when I search for an ID not present in the array.</p>
  
  <pre><code>Dim findstudentid As Integer
  Dim didFindIt As Boolean = False
  Integer.TryParse(idTextBox.Text, findstudentid)
  
  If findstudentid &lt;&gt; 0 Then
      Dim foundIt As Integer
      Dim highColumn As Integer = studentArray.GetUpperBound(0)
  
      'search each column of the first row
      For columnID As Integer = 0 To highColumn
          If findstudentid = CDbl(studentArray(0, columnID)) Then
              foundIt = columnID
              didFindIt = True
              Exit For
          End If
      Next
  
      If didFindIt Then
          'read from array and write to interface
          idTextBox.Text = studentArray(0, foundIt)
          nameTextBox.Text = studentArray(1, foundIt)
      Else
          MessageBox.Show("Student data is not found. Please re-enter or add the student data!", "Student Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  
          idTextBox.Focus()
      End If
  Else
      MessageBox.Show("Please enter a student id.", "Student Information", MessageBoxButtons.OK, MessageBoxIcon.Error)
      idTextBox.Focus()
  End If
  </code></pre>