sequential textfile help

daniella

Member
Joined
Apr 13, 2009
Messages
6
Location
england
Programming Experience
Beginner
i'm trying to load a sequential text file into a listbox, and for some reason it won't move onto the next line? instead i get square characters instead

it appears like

picture3ryu.png


where the square characters are, i want it to be an extra line as opposed to just that? here's the code:

Dim YOUREFILE As String = "C:\Documents and Settings\Administrator\My Documents\PROJECTFILES\YOURSTUDENTSCORES.TXT"
Dim objReader As New System.IO.StreamReader(YOUREFILE)
listbox1.Items.Add(objReader.ReadToEnd)
objReader.Close()

here's what the file looks like

picture4xgl.png


thankyou
 

Attachments

  • Picture 3.png
    Picture 3.png
    94.2 KB · Views: 23
  • Picture 4.png
    Picture 4.png
    74.7 KB · Views: 23
Here's a couple ways you could go about it.

Looping through and adding to the items collection line by line.

VB.NET:
		Using sr As New IO.StreamReader(YOUREFILE)
			While sr.Peek <> -1
				Me.ListBox1.Items.Add(sr.ReadLine)
			End While
		End Using

Using AddRange with a string array.

VB.NET:
		Using sr As New IO.StreamReader(YOUREFILE)
			Me.ListBox1.Items.AddRange(sr.ReadToEnd.Split(Environment.NewLine))
		End Using
 
Back
Top