How to find last 120 lines in a text file
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 'Text File Handling - How to find last 120 lines in a text file Private Sub Command1_Click() Dim strVBlogfile$, strText$, i& Dim arLines() As String strVBlogfile = "full path and name of your file goes in here" If Dir$(strVBlogfile) <> "" Then Open strVBlogfile For Input As #1 'read entire file into string variable strText = Input(LOF(1), #1) Close #1 End If 'split text into array arLines = Split(strText, vbNewLine) 'print what you need If UBound(arLines) > 120 Then For i = UBound(arLines) - 120 To UBound(arLines) Printer.Print arLines(i) Next i Else For i = 0 To UBound(arLines) Printer.Print arLines(i) Next i End If End Sub |