我在学校做 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
端模块