Da moe
05-23-2003, 10:09 AM
Hello All :)
I have simple code to search for certain txt in a txt file using a module for excel
Open "infile.txt" For Input As #1
Open "output.txt" For Output As #2
TextToFind = "xxxx"
Do Until EOF(1)
Line Input #1, data
If InStr(1, data, TextToFind) Then
Print #2, data
End If
Loop
Close
End Sub
How could i code to when "xxxx" is found, it also takes the line of text above it.(or all the text data until is reaches a null line in the text file) So below i have txt at aaa. bbb. ccc. ddd. when i run the code above it outputs bbbbbbbb- xxxxxx & ddddd - xxxxxx since "xxxx" is the text i am looking for.. but how do i also caputure the txt aaaaa, & ccccc, since it is related to the text files i have. Is there a way to search for "xxxx" and when found, it takes all the text until it finds a break, or space between each group of txt files?
aaaaaaaaa
bbbbbbbbb - xxxxxx
ccccccccc
ddddddddd - xxxxxxx
eeeeee
fffffffff - xxxxxx
gggggg
hhhhhh - xxxxxxx
hehe, hope that makes sense
Thanks :)
I have simple code to search for certain txt in a txt file using a module for excel
Open "infile.txt" For Input As #1
Open "output.txt" For Output As #2
TextToFind = "xxxx"
Do Until EOF(1)
Line Input #1, data
If InStr(1, data, TextToFind) Then
Print #2, data
End If
Loop
Close
End Sub
How could i code to when "xxxx" is found, it also takes the line of text above it.(or all the text data until is reaches a null line in the text file) So below i have txt at aaa. bbb. ccc. ddd. when i run the code above it outputs bbbbbbbb- xxxxxx & ddddd - xxxxxx since "xxxx" is the text i am looking for.. but how do i also caputure the txt aaaaa, & ccccc, since it is related to the text files i have. Is there a way to search for "xxxx" and when found, it takes all the text until it finds a break, or space between each group of txt files?
aaaaaaaaa
bbbbbbbbb - xxxxxx
ccccccccc
ddddddddd - xxxxxxx
eeeeee
fffffffff - xxxxxx
gggggg
hhhhhh - xxxxxxx
hehe, hope that makes sense
Thanks :)