|
-
Dec 23rd, 2010, 09:27 PM
#1
Thread Starter
Junior Member
[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.
Last edited by n_minus_one; Dec 23rd, 2010 at 09:36 PM.
Reason: more info
-
Dec 23rd, 2010, 09:44 PM
#2
Thread Starter
Junior Member
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.
-
Dec 23rd, 2010, 11:34 PM
#3
Fanatic Member
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
If I helped you out, please take the time to rate me 
-
Dec 25th, 2010, 12:46 PM
#4
Thread Starter
Junior Member
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?
-
Dec 29th, 2010, 04:49 AM
#5
Fanatic Member
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
If I helped you out, please take the time to rate me 
-
Dec 29th, 2010, 11:26 AM
#6
Thread Starter
Junior Member
Re: [RESOLVED] F8 (stepping)executes only first DIM stmt and that's it
Tags for this Thread
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
|