Hello, I got this application which is writing stuff in a file....with .WriteLine.... after reading the file in the listbox with .ReadToEnd I noticed .WriteLine leaves a terminator (????) It causes major problems in my applicaiton when I tried to use
if not listbox.items.contains because the value got something garbage in the end (terminator?).... what should I do ? I dont want to leave any terminators in my file....tough when I edited the file with notepad there werent any marks of terminators.... but I saw some weird symbol in end of some of the listbox values as shown in the pic at the end...
This is how I read the stuff from the file to a ListBox:
(The values are separated with ; in the file)
if not listbox.items.contains because the value got something garbage in the end (terminator?).... what should I do ? I dont want to leave any terminators in my file....tough when I edited the file with notepad there werent any marks of terminators.... but I saw some weird symbol in end of some of the listbox values as shown in the pic at the end...
This is how I read the stuff from the file to a ListBox:
(The values are separated with ; in the file)
Code:
Dim HSL_Array() As String
Dim HSL_String As String
Dim SR As StreamReader
Dim FileHandle As File
Dim i As Integer
Dim ArraySplit As String
Dim FilterListBox As New ListBox
Read the stuff from the file in HSL_String
If FileHandle.Exists("Calibration.ini") Then
SR = FileHandle.OpenText("Calibration.ini")
HSL_String = SR.ReadToEnd
SR.Close()
Separate the values with splitting the string in the HSL_Array
HSL_Array = HSL_String.Split(";"c)
Now write the array values in a listbox....
For i = 0 To HSL_Array.Length - 1
ListBox1.Items.Add(HSL_Array(i)) testbox
ArraySplit = HSL_Array(i)
FilterListBox.Items.Add(ArraySplit)
Next i
Clear the HSL_Array because it is not needed anymore
HSL_Array.Clear(HSL_Array, 0, HSL_Array.Length)
End If[/VB]
And This is how I write in the file:
[VB] Private Sub Calibrate()
Dim i As Integer
Dim dataString As String
Dim fileDataString As String
Dim FileHandle As File
Dim SR As StreamReader
Dim SW As StreamWriter
Read the new stuff from the listbox in dataString
For i = 0 To lstHSL1.Items.Count() - 1
If dataString = Nothing Then
dataString = lstHSL1.Items(i)
Else
dataString = dataString + ";" + lstHSL1.Items(i)
End If
Next i
Read the old stuff from the file into fileDataString
If FileHandle.Exists("Calibration.ini") Then
SR = FileHandle.OpenText("Calibration.ini")
fileDataString = SR.ReadToEnd
SR.Close()
End If
Write the old stuff (fileDataString) + the new stuff(dataString) in the file.....
SW = FileHandle.CreateText("Calibration.ini")
If fileDataString = Nothing Then
SW.WriteLine(dataString)
Else
SW.WriteLine(fileDataString + ";" + dataString)
End If
SW.Close()
End Sub[/VB]
Attachments
Last edited by a moderator: