P
Petter L
I have set up a test program on how to use colletions saved and loaded from
a file. It was a part of a other program until this happends.
The saving process working fine but it looks like something goes wrong in
the read and refill the listbox. Say there is three items listed in the
file. It semes that the reading process works but I only get the last item
three times insted of three different one.
This is the reading code that was put in a module
Public Excludelist As New ExListCollection
Public Fexclude As New ExFile
Dim path As String = "c:\MyTest.txt"
Dim fs As FileStream
Public Sub ReadExclude()
Try
Dim sr As StreamReader = File.OpenText(path)
Dim inp As String
Do While sr.Peek() >= 0
Fexclude.ExFilename = sr.ReadLine
Excludelist.Add(Fexclude)
MessageBox.Show(Fexclude.ExFilename)
Loop
sr.Close()
Catch e As Exception
MessageBox.Show("The process failed: {0}", e.ToString())
End Try
End Sub
And this was put in the forms form_Load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim count As Integer
ReadExclude()
For count = 0 To Excludelist.Count - 1
MessageBox.Show("List " & Excludelist.Item(count).ExFilename)
lstExclude.Items.Add(Excludelist.Item(count).ExFilename)
Next
End Sub
It looks like the collection as got the data from the file right but when it
is presented again it get wrong.
Have someone any clue what is wrong her ?
PetterL
a file. It was a part of a other program until this happends.
The saving process working fine but it looks like something goes wrong in
the read and refill the listbox. Say there is three items listed in the
file. It semes that the reading process works but I only get the last item
three times insted of three different one.
This is the reading code that was put in a module
Public Excludelist As New ExListCollection
Public Fexclude As New ExFile
Dim path As String = "c:\MyTest.txt"
Dim fs As FileStream
Public Sub ReadExclude()
Try
Dim sr As StreamReader = File.OpenText(path)
Dim inp As String
Do While sr.Peek() >= 0
Fexclude.ExFilename = sr.ReadLine
Excludelist.Add(Fexclude)
MessageBox.Show(Fexclude.ExFilename)
Loop
sr.Close()
Catch e As Exception
MessageBox.Show("The process failed: {0}", e.ToString())
End Try
End Sub
And this was put in the forms form_Load
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim count As Integer
ReadExclude()
For count = 0 To Excludelist.Count - 1
MessageBox.Show("List " & Excludelist.Item(count).ExFilename)
lstExclude.Items.Add(Excludelist.Item(count).ExFilename)
Next
End Sub
It looks like the collection as got the data from the file right but when it
is presented again it get wrong.
Have someone any clue what is wrong her ?
PetterL