How to count number of 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 | 'Text File Handling - How to count number of lines in a text file Public Function CountLineInTxtFile(ByVal strTxtFilePath As String) As Integer Dim strTxt As String Dim strLines() As String 'Open the text file On Error GoTo CountLineInTxtFile_Error Open strTxtFilePath For Input As #1 'load the text file in strTxt variable strTxt = Input(LOF(1), 1) 'close the text file Close #1 'store the lines strLines = Split(strTxt, vbCrLf) CountLineInTxtFile = UBound(strLines) - LBound(strLines) On Error GoTo 0 Exit Function CountLineInTxtFile_Error: MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure " &_ "CountLineInTxtFile of Module Module1" End Function |
Related posts:
- How to replace a line for particular line number
- How to Extract each and every word individually from a text file
- How to Search & Replace the Line for Given Search String in a text file
- Search & Delete the Line for Given Search String in a text file
- How to Remove all empty lines from the text file
- How to load a text file into list box for a given file name
- How to find last 120 lines in a text file
- How to I create a text file from part of another text file (for given line numbers like Line No. 2 to 7)
- How to Read Line By Line & Retrieve Each Word From Text File
- How to read text file contents for a given file (in four ways)