title: VB - Searching a text file
body: <p>I am doing VB at school and we are searching a text file. However, if no results are found, I want to output "There are no results" ONCE. I have tried it but it outputs it for every line of code in the text file. How would I do this?</p>
  
  <pre><code>Module Module1
  Dim townname, findtown, findname, teamname, coachname, phone As String
  Dim choice As String
  Sub Main()
  
      Do
          Console.WriteLine("Please pick an option:")
          Console.WriteLine("1. Search team by team name - Press 1")
          Console.WriteLine("2. Search team by town name - Press 2")
          Console.WriteLine("3. End Program - Press 3")
  
          choice = Console.ReadLine
  
          Select Case choice
  
  
              Case 1
                  Console.Write("Enter the team name:")
                  findname = Console.ReadLine()
                  FileOpen(1, "TeamdataFile.txt", OpenMode.Input)
  
                  Do
                      Input(1, teamname)
                      Input(1, townname)
                      Input(1, coachname)
                      Input(1, phone)
  
                      If teamname.ToLower = findname.ToLower Then
  
                          Console.WriteLine("Team: {0}, from {1}, coach: {2}, contact: {3}", teamname, townname, coachname, phone)
                      End If
  
                  Loop Until EOF(1)
                  FileClose(1)
                  Console.ReadLine()
  
              Case 2
                  Console.Write("Enter the town the team is from:")
                  findtown = Console.ReadLine()
                  FileOpen(1, "TeamdataFile.txt", OpenMode.Input)
  
                  Do
                      Input(1, teamname)
                      Input(1, townname)
                      Input(1, coachname)
                      Input(1, phone)
  
                      If townname.ToLower = findtown.ToLower Then
                          Console.WriteLine("Team: {0}, from {1}, coach: {2}, contact: {3}", teamname, townname, coachname, phone)
                      End If
  
                  Loop Until EOF(1)
                  FileClose(1)
                  Console.ReadLine()
              Case 3
                  End
              Case Else
                  Console.WriteLine("Invalid option - Choose option 1 or 2 or 3")
          End Select
      Loop Until choice = "1" Or choice = "2" Or choice = "3"
  End Sub
  </code></pre>
  
  <p>End Module</p>