Content Obsolete

This content is no longer current. Our recommendation for up to date content: http://channel9.msdn.com/Series/Visual-Basic-Fundamentals-for-Absolute-Beginners

While Iterations and Reading Data from a Text File - 11

Download this episode

Download Video

Download captions

Download Captions

Description

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....

Embed

Format

Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image
      karim

      Always great BOB
      very intuitive, nice explanation
      wishes from Morocco

    • User profile image
      golnazal

      open.

    • User profile image
      harry

      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,

      Harry

    • User profile image
      BobTabor

      @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
      Rick

      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
      ZeroShek

      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
      Beth

      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
      meldoc

      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()
      Console.WriteLine(line)
      Loop

      myReader.Close()
      Console.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
      BobTabor

      @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:

      http://msdn.microsoft.com/en-us/library/aa720461(v=vs.71).aspx

    • User profile image
      jueban

      so good!

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.