Results 1 to 2 of 2

Thread: Can I search a text file for a specific string?

  1. #1


    I have a text file with names in it. Is it possible for VB 6.0 to search through the text file for a last name I enter, and then read the whole line that the last name is on (to get the first name next to it) and then to output that to a separate file? Thanks!

  2. #2
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Western NY State
    Dim FF
    Dim tmpLine As String
    Dim LineToSave As String
    FF = FreeFile()
    Open YOUR-TXT-FILE For Input As #FF
        Do While NOT(EOF(FF))
            Line Input #FF, tmpLine
            If InStr(1, tmpLine, Text1.Text) > 0 then
                'Put code here to pull the first name.
                'Since you have the position of the last name, you
                'can use mid to pull the first name:
                'FirstName = Mid(tmpLine, (position of first name), (position of last name -1))
                LineToSave = tmpLine
                Close #FF
            End If
    Close # FF
    FF = FreeFile()
    Open YOUR-NEW-TXT-FILE For Output As #FF
        Print #FF, LineToSave
    Close #FF
    I haven't verified this, but if you know how to open a file and read it line by line, the rest of the code should work for you. Hope it helps.

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