+92 332 4229 857 99ProjectIdeas@Gmail.com

Count Lines In File (Vb.net)

The following code shows counting a lines of text in file. Strategy is that: reading a file line by line and plus the counter by 1.

Imports System.IO

Public Sub CountLines(ByVal filePath As String)

        Dim tr As TextReader = File.OpenText(filePath)

        Dim line As Integer = 0

        While Not tr.ReadLine() Is Nothing

            line += 1

        End While


End Sub