ReadLine in Reverse

  • Thread starter Thread starter Mike Archer
  • Start date Start date
M

Mike Archer

Is there a way to read a text file from the bottom up? I have a text file
that is going to get very big, and I am only interested in reading the bottom
of the file. And I would like to reverse the order so that the last entry is
displayed first.
 
How big is "very big"? Also, "displayed first" where? How many lines
represents "the bottom of the file"?

If "very big" file is under, say, 10-15 Megs, this approach should work fine
(15 to 50 Megs will work too; but speed, or lack thereof, may start to
become a concern)...

Sub GetEndOfFile()
Dim X As Long
Dim FileNum As Long
Dim TotalFile As String
Dim Records() As String
FileNum = FreeFile
Open "c:\temp\YourTextFile.txt" For Binary As #FileNum
TotalFile = Space(LOF(FileNum))
Get #FileNum, , TotalFile
Close #FileNum
Records = Split(TotalFile, vbCrLf)
'
' At this point, the Records array contains each "paragraph",
' which I'm guessing would be your "entry"; just read it from
' last entry upward and put it wherever you want. Something
' like this (using a TextBox as your display vehicle)...
'
' For X = UBound(Records) To Ubound(Records) - 10 Step -1
' TextBox1.Text = TextBox1.Text & vbCrLf & Records(x)
' Next
End Sub

Rick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top