|
-
Oct 9th, 2003, 12:17 PM
#1
Thread Starter
Addicted Member
Simple question (I Hope)
All im trying to do is make this function to return how many lines are in the log file. I had this working perfect in vb6 and had some NIMROD idea to try and learn some .NET and now im sort of stuck on it.
This is what Ive come up with so far but all that happens is it seems to loop forever.
VB Code:
Public Function LogSize(ByVal pLog As String) As Long
Dim x As Long
Dim sTmp As String
Dim oFile As New System.IO.FileStream(pLog, IO.FileMode.Open)
Dim oRead As New System.IO.StreamReader(oFile)
Do While oRead.Read
sTmp = oRead.ReadLine
x = x + 1
Loop
LogSize = x
oRead.Close()
End Function
Thanks for looking
-------------------------
My name says it all!
-
Oct 9th, 2003, 12:29 PM
#2
Addicted Member
I'm at work right now an can't check to see if this is right but try it an see
VB Code:
Public Function LogSize(ByVal pLog As String) As Long
Try
Dim sr As StreamReader = New StreamReader(pLog)
Dim line As String, lines As Long
line = sr.ReadLine()
Do
lines += 1
line = sr.ReadLine()
Loop Until line Is Nothing
sr.Close()
return lines;
Catch e As Exception
' In case of error
MessageBox.Show("Exception Occurred: " & vbcrlf & e.Message)
Return -1;
End Try
End Function
-
Oct 9th, 2003, 12:50 PM
#3
You can also use split instead of looping:
VB Code:
Private Function GetLineCount(ByVal filepath As String) As Integer
Dim sr As New IO.StreamReader(filepath)
Dim data As String = sr.ReadToEnd
sr.Close()
Return data.Split(ControlChars.NewLine).Length
End Function
-
Oct 9th, 2003, 01:16 PM
#4
Thread Starter
Addicted Member
Thanks both for the input... .Net is driving me nuts.
-------------------------
My name says it all!
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
|