Listbox reading problem?

ukjock

Active member
Joined
Dec 10, 2003
Messages
35
Location
Scotland
I am able to write to a text file no problem. it stores it in the manner that i require:

14/12/2003 | 16:12 | HEARTS VERSUS HIBS
14/12/2003 | 16:12 | LAVINE SHOULD BE FORCED TO RESIGN
14/12/2003 | 16:12 | LAVINE SHOULD QUIT


When i open the text file to be read in a listbox they appear like so:

14/12/2003 | 16:12 | HEARTS VERSUS HIBS14/12/2003 | 16:12 | LAVINE SHOULD BE FORCED TO RESIGN 14/12/2003 | 16:12 | LAVINE SHOULD QUIT

it actually goes out of the listbox and I can only read a small amount instead of multiple lines.


my code is :

Dim H As New History
Dim a As AddCaller
Dim sr As New IO.StreamReader(New IO.FileStream(Application.StartupPath & "\Logs\Caller_history\" & TextBox4.Text & ".txt", IO.FileMode.OpenOrCreate))
Dim textfromfile As String = sr.ReadToEnd()
H.ListBox1.Items.Add(textfromfile)
sr.Close()
H.Visible = True


is this becuase i am only adding the text file as 1 item and not multiple? If so how do i go around doing multi line adding from a textbox? is it fairly straight forward.

Thanks

Chris
 
You can do it like this:
Code:
 read as long as there is anything to read from the file
Do While reader.Read()
   use the read line method to read a line from the file
   ListBox1.Items.Add(reader.ReadLine())
Loop
 
Back
Top