While Iterations and Reading Data from a Text File - 11
- Posted: Nov 21, 2011 at 9:26 AM
- 24,705 Views
- 11 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
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....
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.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
Always great BOB
very intuitive, nice explanation
wishes from Morocco
open.
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
@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.
Thank you and best wishes to your students!
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.
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.
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!
Thank you for this excellent series, a great resource.
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.
@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
so good!
Remove this comment
Remove this thread
close