READ a text file line by line and store it into string if a particular pattern is found ,then output the pattern into differnt string ?

Dim file_id As Integer
Dim strline As String
Dim array_item() As String

'Open file
file_id = FreeFile

Open "D:\input.txt" For Input As #file_id

Dim i As Integer
i = 0

Do Until EOF(file_id)

Line Input #file_id, strline

ReDim Preserve array_item(i)

array_item(i) = strline

i = i + 1
Loop

Close #file_id
End Sub

Edited 3 Years Ago by ponnu

so, What wrong with your code? any errors?
What you mean about "particular pattern"?
Post your text file sample.

to find the pattern just loop through your array with a for loop and compare the string with your pattern.

Edited 3 Years Ago by tinstaafl

Try putting this in your loop:

If InStr(strline, "pattern", vbTextCompare) Then
    <do whatever you want with it here>
end if

I think that will do away with the array then.

Dim FileNum As Integer
Dim DataLine As String

FileNum = FreeFile()
ctr = 13
Open "Directory\of\file.text" For Input As #FileNum 'Opening a text file using macro

While Not EOF(FileNum) 'check if end of file
Line Input #FileNum, DataLine ' read in data 1 line at a time

Wend

try this..
Dont forget to mark this solve your problem is solve.

happy coding

This question has already been answered. Start a new discussion instead.