Results 1 to 2 of 2

Thread: [RESOLVED] Counting Lines

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    England
    Posts
    79

    Resolved [RESOLVED] Counting Lines

    Is there a function in VB.NET which will count how many files there are in a Text File? If not, does anyone know of some code I can use to do this?

    Many thanks.

    [EDIT]

    Nevermind guys, I found this:

    VB Code:
    1. Dim sr As StreamReader = File.OpenText("file.txt")
    2. Dim LineCount As Integer = 0
    3. While Not (sr.ReadLine() Is Nothing)
    4. LineCount += 1
    5. End While

    which works fine
    Last edited by Cyber-Drugs; Jul 18th, 2005 at 04:59 AM.

  2. #2
    Hyperactive Member
    Join Date
    Mar 2005
    Location
    Bath, England
    Posts
    411

    Re: Counting Lines

    VB Code:
    1. Public Function GetLineCount(Byval Filename As String) As Long
    2.    Return New IO.StringReader("C:\MyTextFile.txt").ReadToEnd.Split(vbNewLine).GetUpperBound(0) + 1
    3. End Function
    Note that this doesn't check that the file exists, make sure it does before calling the function.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width