Reading from a txt file

frustrating

Registered User.
Local time
Yesterday, 18:35
Joined
Oct 18, 2012
Messages
68
Greetings:

I am working on an application that converts various formats into text files after they've been OCR'd for parsing. One thing I need to do is find something in the text file and then go to the next line and combine that line with the line i searched for. Is this possible to do?

Here's a piece of what I have going on:
Code:
CertEnd = FreeFile
Open Text1.Value For Input As CertEnd
Do Until EOF(CertEnd)
Line Input #CertEnd, TheCert



CarrierPlace = InStr(1, TheCert, "INSURED")
If CarrierPlace > 0 Then
CarrierName = Mid(TheCert, CarrierPlace + 8, 50)
'I would then like it to go to the next line in the text file and copy that as well.
End If
Loop
Any ideas?
 
Not sure if this is what you want, but given a text file (named LineTest) like this (with some garbage plus a few lines we care about in red);

dfkgjalgl;jsl
sdflsljsdsjgf
sdflslfjljsdg
slksjlkzln
Insured On This Line
This is the next line
ljsdgljsafg
aslkjlsgf
afjgf
asfksdjfjsaf
lksdjflsjf
ljsafljf
sg;skag;kglkg
Insured Again
Another Line
lksadjflksajf
sadpfjs;djf

Then code like the following;

Code:
Dim strFileName As String, strLineData As String, strTempString As String
Dim MyFile As Long
Dim i As Integer, x As Integer


strFileName = "C:\Users\sbailey\My Documents\LineTest.txt"
MyFile = FreeFile
Open strFileName For Input As #MyFile
    Do While Not EOF(MyFile)
    Line Input #MyFile, strLineData
        If i = 1 Then
            strTempString = strTempString & " " & strLineData
            Debug.Print strTempString
        End If
        x = Nz(InStr(1, strLineData, "Insured"), 0)
        If x > 0 Then
            i = 1
            strTempString = Mid(strLineData, x)
        Else
            i = 0
        End If
    Loop
Close #MyFile

Give these results in the immediate window;

attachment.php
 

Attachments

  • Immediate.jpg
    Immediate.jpg
    18 KB · Views: 139
This does help me a great deal! I'm trying to wrap my head around why this works.

Thanks, though!
 
I'm trying to wrap my head around why this works.

On each loop, if you encounter something you're looking for in the current line of text, set a variable (in this case i) to 1, otherwise set it to 0. On the next loop, if the variable = 1 that means you found something you wanted in the previous line so extract something from this line as well.
 
Interesting. I never would've thought about doing it this way in a million years.

You're like a genie.
 
You're like a genie.

If I was a genie I would wish myself to be on a beach drinking a beer.

Wait, let me try...............................

Damn! No beach. :(

Double Damn! No beer either! :(
 

Users who are viewing this thread

Back
Top Bottom