Text file inputting: begin from the end or skipping lines?

Text file inputting: begin from the end or skipping lines?

Post by QUs » Thu, 23 Feb 2006 00:11:27


Hi,

I'm importing a large text file to Access. I'd like to start reading the
file beginning from the end, as I normally need need only approx. the last
1000 lines (and reading the other lines is just time consuming).

Now I'm forced to read all the lines:

Open fileName For Input As FID
Line Input #FID, Buffer
While Not EOF(FID)
prosessLine (Buffer)
Wend

If it is not possible, it would also be helpful if I could read for example
every 100th line and, when information new enough is found, read all lines
from that on (and the 99 lines before that).

Every line contains over 1000 char (including the date, which I use as
indetificator), so reading all >10000 lines is really time burdening!

Thanks in advance,
Anssi K.
 
 
 

Text file inputting: begin from the end or skipping lines?

Post by Tim Fergus » Thu, 23 Feb 2006 01:00:24


XXXX@XXXXX.COM :


You might find it handy to write an indexer for the file; otherwise if you
know exactly how long each line is, you could treat it as a binary file and
Seek straight into it.

You could use Seek to start, say, three quarters of the way through and the
read up to the nearest vbNewLine sequence. Your algorithm would need to be
able to back track if your starting point turned out to be too far on.

My guess would just be to read each line into a collection of strings, and
delete the 1st every time you get to 101.

All the best


Tim F

 
 
 

Text file inputting: begin from the end or skipping lines?

Post by John Nuric » Thu, 23 Feb 2006 02:07:45

For really big files I'd shell out to some serious text-processing
tools, but with only 10,000 lines something like this *air code* should
work OK:

Dim j As Long, FilePos As Long
Dim InterestingLineFound As Boolean

Open FN For Input As FID
InterestingLineFound = False
Do Until InterestingLineFound = True Or EOF(FID)
j = 0
FilePos = Seek(FID)
Do Until j = 100 or EOF(FID)
Line Input #FID, Buffer
j = j + 1
Loop
'test contents of Buffer.
If we're in the area of interest Then
InterestingLineFound = True
End If
Loop

If EOF(FID) Then exit sub

'If we're here, we've found an interesting line
'but have probably overshot
Seek #FID, FilePos 'go back to our last bookmark

'Process the remaining lines
...

On Tue, 21 Feb 2006 07:11:27 -0800, "AK" < XXXX@XXXXX.COM >



Please respond in the newgroup and not by email.
 
 
 

Text file inputting: begin from the end or skipping lines?

Post by LanceMcGon » Thu, 23 Feb 2006 05:06:51

If the file is a structured file then you could link to it (like you do a
table in another database) and query it in reverse sequence. Just establish
the link and run the query as an input set to your code.

cheers



example