470,587 Members | 1,695 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,587 developers. It's quick & easy.

Searching for a value in a text file

I am trying to search for a number >= to some vale in a text file. The code is failing to work.

Sub SearchFileNumber()
Dim CarRegistration As String = ""
Dim DateSold As String = ""
Dim NumberOfRepairs As String = ""
Dim Found As Boolean = False
Dim SearchString As String
Dim FileHandle As IO.StreamReader
FileHandle = New IO.StreamReader("CARSALES.TXT")
Console.WriteLine("Enter Number of Repairs")
SearchString = Console.ReadLine
While Not FileHandle.EndOfStream
Dim line As String = FileHandle.ReadLine()

If Val(NumberOfRepairs) >= Val(SearchString) Then
Console.WriteLine(line)
Found = True
End If

End While
If Found = False Then
Console.WriteLine("No cars found")
End If
Console.ReadKey()
FileHandle.Close()
Main()
End Sub

The above is the code i came up with. Please help
Aug 31 '16 #1
0 770

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.