This code displays the last line of a text file in a message box. Basically, it shows everything after the last linefeed.
Dim Fname As String, LastLine As String
Dim Fnum As Long, i As Long
Dim CarRet As String
Fname = “C:DickTesterFindLast2.txt”
Fnum = FreeFile
Open Fname For Input As Fnum
For i = LOF(Fnum) To 1 Step -1
Seek #Fnum, i
CarRet = Input(1, #Fnum)
If CarRet = vbCr Or CarRet = vbCrLf Then
Line Input #Fnum, LastLine
I’ve never really had occasion to use this, except to answer a newsgroup post a while back (His last line was a date stamp, that’s why this procedure has a funny name). But it does demonstrate some of the text file handling functions that are available.
The poster who needed this had a very large text file, so starting from the top to get to the last line wasn’t an option for him. Seek to the rescue.