Filtering a text file

The example in this section demonstrates how to work with two text files at once. The FilterFile procedure that follows reads a text file (infile.txt) and copies only the rows that contain a specific text string to a second text file (output.txt).

Sub FilterFile()

Open "infile.txt" For Input As #1 Open "output.txt" For Output As #2 TextToFind = "January" Do Until EOF(1)

Line Input #1, data

If InStr(1, data, TextToFind) Then

Print #2, data End If

Loop Close End Sub

This example is available on the companion CD-ROM.

0 0

Post a comment