Talk2Tom11 Posted September 14, 2005 Posted September 14, 2005 I want to open a .txt file and just get the number of lines that it contains. Not the specific information within the lines. But just a line count. How would i go about that? Quote
mskeel Posted September 14, 2005 Posted September 14, 2005 Assuming this is in a method called something meaningful like GetNumberOfLines(byval fileName As String)...From the hip: Dim sr as StreamReader = Nothing Try sr = New StreamReader(fileName) Dim numberOfLines As Integer = 0 ''read the line, don't care about the value so don't bother storing it While Not sr.ReadLine() Is Nothing numberOfLines += 1 End While return numberOfLines Catch ex As Exception ''something went wrong Finally If not sr Is Nothing Then sr.Close() End If sr = nothing 'paranoid End Try Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.