StreamReader+2+(VB)

Private Sub cmdShowAll_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShowAll.Click Dim sRead As IO.StreamReader = New IO.StreamReader( "G:\Addresses.doc" ) Dim strAllFile As String = "" Do While sRead.Peek <> -1 strAllFile = strAllFile & sRead.ReadLine & vbNewLine Loop MsgBox(strAllFile) sRead.Close End Sub
 * This program will read the information in from a text file.**
 * Specifying which file to read, and its location.**
 * Peek ahead, to ensure that there is still content to read!**
 * Read through the text file, and read in each line, then move onto the next line!!!!!**
 * Display in a message box, all of the text!!!!!!**

code  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 * Dim StreamToDisplay As StreamReader **
 * StreamToDisplay = New StreamReader("H:\Test.txt") **
 * Label1.Text = StreamToDisplay.ReadToEnd **
 * StreamToDisplay.Close **

' Create a StreamReader object (a object that has the ability to read text) Dim r As IO.StreamReader = New IO.StreamReader("c:/Soccer/SoccerRegistration.txt") ' Store contents in this String. Dim line As String Dim List As New List(Of String)

' Read first line. line = r.ReadLine

' Loop over each line in file, While list is Not Nothing. Do While (Not line Is Nothing) ' Add this line to list. List.Add(line) ' Display to console. Console.WriteLine(line) ' Read in the next line. line = r.ReadLine Loop

End Sub code