Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21278

[RESOLVED] VB6 Search a text file for a string of text then read the rest of the file

$
0
0
Hi all,

I came across this website via Google trying to find a solution to a problem I have. I dabble with VB, tweaking existing snippets of code to 'make it fit' but I find myself this time with a blank canvass and no examples to tweak from. That's about the extent of my knowledge. Would anyone be so kind as to help me please?

The problem I have is this:

I have a file called LOG.txt (approx 8-10kb in size) and an example of this file would be:
Code:

useless information
useless information
useless information
useless information
useless information

**************
RESULT SUMMARY
**************
useful information
useful information
useful information
useful information
useful information
useful information
useful information

*******************************************
EOF

I want to read this file and I want to create a string called 'Text1' that contains all the information from the RESULT SUMMARY section of the file, right down to the end of the file.

so effectively, my Text1 string would result in containing this (dropping all of the usless info above it):

Code:

**************
RESULT SUMMARY
**************
useful information
useful information
useful information
useful information
useful information
useful information
useful information

*******************************************

I know it must be simple enough, I just can't find the right combination of code to do my usual 'make it fit' for my purpose.

The theory of what I think I may need to do is this:
  • Do a search for the string within the file
  • Find out the line number
  • Jump up two lines (to go above the asterisks)
  • Then read the rest, line by line


Would this be an effective way of doing this? Or would putting it into an array work more efficiently?
Please note that the information may move up and down the text file and is not consistently on line # x

Following the FAQ on another site, I thought about trying an Array but had no luck:

Code:

Dim MyArray() As String
Dim MyString As String
Dim FF As Integer

FF = FreeFile()
Open ("c:\Reports\log.log") For Binary As FF

ReDim MyArray(LOF(FF))
Get FF, , MyArray

'Break the string by commas
MyArray = Split(MyString, "RESULT SUMMARY")
Text1 = MyArray(1)
Close FF

I thought I'd try and be cheeky and set my delimiter to the text I am looking to split from, but I seem to get a blank result in my string, Text1

Thanks in advance for any help given.

Viewing all articles
Browse latest Browse all 21278

Trending Articles