私は学校で VB をやっていて、テキスト ファイルを検索しています。ただし、結果が見つからない場合は、「結果がありません」を一度だけ出力したいです。試してみましたが、テキスト ファイルのコード行ごとに出力されます。どうすればいいですか?
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
エンドモジュール