[RESOLVED] F8 (stepping)executes only first DIM stmt and that's it
Code:
'global declaration
Dim FILE_NAME As String = "EventList.txt"
Dim PATH_FILE As String = Environment.CurrentDirectory() & "\" & FILE_NAME
'end of global declaration
Private Sub ProcessFiles()
Dim fs As New FileStream(PATH_FILE, FileMode.Open, FileAccess.Read)
Dim sr As New StreamReader(fs)
Dim TextLine As String 'line from file
MsgBox(PATH_FILE)
Do Until sr.EndOfStream()
TextLine = sr.ReadLine
MsgBox(TextLine)
Loop
End Sub
Using F8 to step through all of the code, it gets to this sub, highlites Dim fs ...
and then hit F8 again it just pops up the form, no message boxes - nothing. Other notes: EventList does exist in stated directory.
Any ideas why it wouldn't complete the sub?
the first debug line after hit the f8 is:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
...but the file is there! all 14kb of it.
Re: F8 (stepping)executes only first DIM stmt and that's it
Ok. the file was there, just with an extra ".txt" on it - which you can't see because that's the way win7 displays it by default. Sorry for the confusion.
Re: [RESOLVED] F8 (stepping)executes only first DIM stmt and that's it
Glad it's resolved, but I just thought I'd point out that you didn't close your StreamReader or the FileStream after using them. It's always a good idea with objects like the StreamReader to create it, use it and then dispose it. Using-End Using is a handy way of achieving it:
vb Code:
Using fs As New FileStream(PATH_FILE, FileMode.Open, FileAccess.Read)
Using sr As New IO.StreamReader(fs)
Do Until sr.EndOfStream()
TextLine = sr.ReadLine
MsgBox(TextLine)
Loop
End Using
End Using
Re: [RESOLVED] F8 (stepping)executes only first DIM stmt and that's it
Thanks J-Deezy. I'll be including that. So the end using tokens actually do the work of disposing the objects or is there an actual dispose token required to guarentee that?
Re: [RESOLVED] F8 (stepping)executes only first DIM stmt and that's it
End Using disposes the object, even if an exception is thrown in the method which forces the method to be exited prematurely. It's really quite handy :)
Re: [RESOLVED] F8 (stepping)executes only first DIM stmt and that's it