Results 1 to 6 of 6

Thread: Searching for text in a text file

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2003
    Location
    Tacoma, WA
    Posts
    13

    Searching for text in a text file

    Hi, this will probably be simple for you guys but, I'm trying to search a text file for a last name, and then display the corresponding info underneath the name from the text file such as phone number, address, etc...After it finds it, it then displays it neatly in a windows form. I can't get it to work though..this is what I have so far.


    VB Code:
    1. Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    2.         Dim input As String 'What I'm searching for
    3.         Dim friendFile As System.IO.StreamReader
    4.         friendFile = System.IO.File.OpenText("database.txt")
    5.         'Use an input box to gain the search string
    6.         input = InputBox("Enter the last name of the data you'd like to see.", "Enter Last Name")
    7.        
    8.         'This will only return true if I search for the first name in the text file, but I want it to be able to go down the entire text file
    9. Do            
    10. If friendFile.ReadLine = input.ToUpper Then
    11.                 txtLastName.Text = input.ToUpper
    12.                 txtFirstName.Text = friendFile.ReadLine()
    13.                 txtCustNumber.Text = friendFile.ReadLine()
    14.             Else : MessageBox.Show("Customer not found.", "Error")
    15.             End If
    16.     Loop Until friendFile.ReadLine() <> input.ToUpper
    17.     End Sub
    Last edited by mccullom; Nov 27th, 2003 at 03:49 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width