|
-
Jul 18th, 2005, 04:51 AM
#1
Thread Starter
Lively Member
[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:
Dim sr As StreamReader = File.OpenText("file.txt")
Dim LineCount As Integer = 0
While Not (sr.ReadLine() Is Nothing)
LineCount += 1
End While
which works fine
Last edited by Cyber-Drugs; Jul 18th, 2005 at 04:59 AM.
-
Jul 18th, 2005, 05:00 AM
#2
Hyperactive Member
Re: Counting Lines
VB Code:
Public Function GetLineCount(Byval Filename As String) As Long
Return New IO.StringReader("C:\MyTextFile.txt").ReadToEnd.Split(vbNewLine).GetUpperBound(0) + 1
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|