Results 1 to 6 of 6

Thread: [RESOLVED] F8 (stepping)executes only first DIM stmt and that's it

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    28

    Resolved [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

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    28

    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.

  3. #3
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    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:
    1. Using fs As New FileStream(PATH_FILE, FileMode.Open, FileAccess.Read)
    2.     Using sr As New IO.StreamReader(fs)
    3.         Do Until sr.EndOfStream()
    4.             TextLine = sr.ReadLine
    5.             MsgBox(TextLine)
    6.         Loop
    7.     End Using
    8. End Using
    If I helped you out, please take the time to rate me

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    28

    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?

  5. #5
    Fanatic Member
    Join Date
    Aug 2010
    Posts
    624

    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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2010
    Posts
    28

    Re: [RESOLVED] F8 (stepping)executes only first DIM stmt and that's it

    thanks, good to know.

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
  •  



Click Here to Expand Forum to Full Width