Count lines in a text file (split method)

Function that will return the amount of lines in a passed text file. This method uses a Split function to push each line of the text file into an array, and then uses the Ubound function to return the upper boundry of the array.

Author: Veign
Language: VBScript
Type: Code Sample
Posted: August 20, 2004
Date Revised:

Code / Download

' ---------------------------------------------------------------
' Copyright ©2000 - 2014 Veign, LLC All rights reserved
' ---------------------------------------------------------------
' Distribution: You can freely use this code in your own
' applications, but you many not reproduce
' or publish this code on any web site,
' online service, or distribute as source on
' any media without express permission from Veign.
' ---------------------------------------------------------------

Function FileLineCount(strFileName)

  'Create a File System Object
  Dim fso
  Set fso = CreateObject("Scripting.FileSystemObject")

  'Get the file contents
  Dim MyFileContents
  Set MyFileContents = fso.OpenTextFile(strFileName)

  'Return the file's line count
  FileLineCount = Ubound(Split(MyFileContents.ReadAll, vbLf))

  Set MyFileContents = Nothing
  Set fso = Nothing

End Function
Disclaimer: If you use any of the source code or compiled applications on this site, you realize that you do so AT YOUR OWN RISK. The items provided here are supplied AS IS and Veign makes no warranty as to its use or performance either expressed or implied.