Content Archived

This content is no longer current. Our recommendation for up to date content:

While Iterations and Reading Data from a Text File - 11

Play While Iterations and Reading Data from a Text File - 11
Sign in to queue


In this lesson we'll both learn a new type of iteration statement (While) and will learn how to utilize the StreamReader class to stream data from a file to the Console window. Additionally, we'll learn how to add new files to our project, how to set properties of our file using the Properties window, how to add a using statement as a means of resolving a class name referenced in our code to the namespace in which it is defined, and more.

Download the source code for While Iterations and Reading....



The Discussion

  • User profile image

    Always great BOB
    very intuitive, nice explanation
    wishes from Morocco

  • User profile image


  • User profile image

    G'day Bob,
    (btw - enjoying the vid's - going to be excellent resources for my students)

    Would it have been "better" (more obvious) to use a "do until IsNothing(line) ... loop" construct rather than the "while ... end while" ? Or perhaps even the "do ... loop until IsNothing(line)" ?

    The "benefit" would be the immediate removal of the "double-negative", which, to be honest, as a vet of 4 decades of coding still trips me up occasionally ;') I know my students struggled with it just last week, hence why it is still "fresh" in my mind :)

    Kind regards,


  • User profile image

    @harry:  Great, great tip!  You're right, I probably could have written than using a different looping structure and made it a "positive" rather than a double-negative.  Smiley  Thank you and best wishes to your students!

  • User profile image

    I have noticed that with Harry's Do until method you no longer need the If then statement also.. Thanks for the tip Harry and thanks Bob for the While method I see where they can both be very useful.

  • User profile image

    I was looking for an open thread to thank you on previous 10 tutorials but all threads were closed....finally got the opportunity ...Thanks for creating tutorials that are so simple yet teaches you a lot...are there videos for WinForms apps too using VB..if yes plz share the link..I'll be very grateful to you..well that is already I'm.

  • User profile image

    Thank you for these great videos! Bob - your delivery is excellent. Great voice, cadence, inflection, etc. Of course it helps that the subject matter is important to me, but that's beside the point!

  • User profile image

    Thank you for this excellent series, a great resource.

  • User profile image
    Kent Haunschild

    Tried Harry's method the Do Until...Loop
    coded like this:
    Dim myReader As StreamReader = New StreamReader("values.txt")

    Dim line As String = ""
    Do Until IsNothing(line)
    line = myReader.ReadLine()

    The program ran I.E. gave the correct output to the display, but with following errors:

    A first chance exception of type 'System.IndexOutOfRangeException' occurred in UnderstandingArrays.exe
    A first chance exception of type 'System.IndexOutOfRangeException' occurred in UnderstandingArrays.exe
    A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

    I realize the lesson was on using the While()...IsNothing but as wondering what else is wrong with my code.

  • User profile image

    @Rick: Agreed.

    @ZeroShek:  Thanks!  I'm sure there are videos out there, but not by me.  Sorry!

    @Beth: Ah, thanks Beth!

    @meldoc: Thank you!

    @Kent Haunschild: Hi!  check this out ... it uses Do ... Loop Until properly:

  • User profile image

    so good!

Add Your 2 Cents