-
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!
-Adam
-
Code:
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
Loop
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.