title: VB.NET Search Text File for Customer Number and display entire customer record in listbox
body: <p>I am new to Visual Basic 2010 and have been banging my head against the wall with this one.</p>
  
  <p>I have a form that accepts user input and saves it to a text file in the following format:</p>
  
  <p>"Customer #:" 00</p>
  
  <p>Doe, John</p>
  
  <p>10350 Some Street</p>
  
  <p>City, State Zip Code</p>
  
  <p>Telephone Number</p>
  
  <p>"Account Balance: $" 00.00</p>
  
  <p>"Date Of Last Payment:" Month/Day/Year</p>
  
  <p>I have a text box where the user inputs either a customer number or last name depending upon which check box is checked. The purpose of this is to search the text file for a customer record by last name or customer number.</p>
  
  <p>When Searched I would like  the customer with the last name or customer number 
  used in the search displayed in a listbox.</p>
  
  <p>Here is the code I have below:</p>
  
  <pre><code>Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)   Handles btnSearch.Click
      'Local Variables
  
      Dim ReadCustomerRecords As StreamReader
      Dim strCustomerNumber As String
  
      ' Validate Search Criteria
      If chkCustomerNumber.Checked = False And chkLastName.Checked = False Then
          MessageBox.Show("Please select either Customer Number OR Last Name" &amp; vbNewLine   &amp; "to narrow your search.", "Attention")
  
      End If
      If chkCustomerNumber.Checked And chkLastName.Checked Then
          MessageBox.Show("You may only search by Customer Number OR Last Name." &amp; vbNewLine &amp; "Please revise your search.", "Attention")
      End If
  
      If chkCustomerNumber.Checked Then
          ReadCustomerRecords = File.OpenText(strCustomerRecordsFile)
          strCustomerNumber = ReadCustomerRecords.ReadLine()
          Do Until strCustomerRecordsFile.Contains(txtSearchFile.Text)
  
              If strCustomerNumber.Contains(txtSearchFile.Text) Then
                  lstCustomerSearch.Items.Add(strCustomerNumber)
                  lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
                  lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
                  lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
                  lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
                  lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
                  lstCustomerSearch.Items.Add(ReadCustomerRecords.ReadLine())
              Else
                  MessageBox.Show("The customer number you entered is not valid." &amp; vbNewLine &amp; "Please try again or search by Last Name.", "Attention")
              End If
              Return
          Loop
          ReadCustomerRecords.Close()
      End If
  
      If chkLastName.Checked Then
          ReadCustomerRecords = File.OpenText(strCustomerRecordsFile)
      End If
  End Sub
  </code></pre>