Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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)

 

           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

 

 

And This is how I write in the file:

 

      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

Edited by DR00ME

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

Posted
btw when the writing sequence ends that damn symbol comes there in the end of the stream....but from where ??????????

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

Posted

you are amazing!! :D

 

P.S. omg those return chars really pissed me off :)

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...