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 ?

Post your code.
How far you doing this.

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

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.

Member Avatar for Lee Chetwynd

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

thanks the problem has been solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.