We all know how to count number of lines in a text file. We can use any one of the below methods to do that.
- Incrementing a counter variable while reading or skipping a line using File System Object (FSO).
- Read all the content using FSO-ReadAll method, split it line by line and put into an array.
- Read the content and count no. of lines using RegExp.
Dim oFile,strFilePath,inLineCount 'Storing File path in strFilePath variable strFilePath="C:test.txt" 'Creating object for .Net IO File class Set oFile=DotNetFactory.CreateInstance("System.IO.File","") 'Counting no. of lines using Length after reading all the lines using ReadAllLines method inLineCount=oFile.ReadAllLines(strFilePath).Length Set oFile=Nothing