Problems with filemode.truncate

hassan1404

Member
Joined
Mar 21, 2006
Messages
6
Programming Experience
1-3
Hi

I am haveing a small problem with writing to a file, I am trying to write the contents of a list box to a file but always end up with a blank line between each line of data.

Can anyone help? I have writtern the code that i am using below:confused:

Dim X As Integer
Dim fsStream As New FileStream("C:/Alarm.txt", FileMode.Truncate, FileAccess.Write)
Dim swWriter As New StreamWriter(fsStream)
X = 0
While X <= lstAlarm.Items.Count - 1
swWriter.WriteLine(lstAlarm.Items(X))
X = X + 1
End While
swWriter.Close()
Me.Close()

This gives a txt file like below only after it has truncated the file. The origanal file created is fine, and called back when the form loads (This file is created when the form is closed)
20:30 18/03/2006

12:34 18/03/2006

12:45 19/03/2006

Many thanks in advance Hassan
 
hey,

I tried u r example but that really worked. Is it that the data in the list box ends up with line break or something.

What type of data u have in List Box ? May be i can help u

- Jay
 
Hi Jay

Thanks for looking into this for me, i have uploaded the entire project folder in a rar format to the following address, if any one wants to download it and have a look at it feel free, The error only ocures when you click "Close" the second time it runs and onwards.

www.sbndesign.co.uk/win.rar

Thanks again
 
You add linefeed characters when you add items to listbox.
 
Thanks John,

I am a little confused, i cant see where i am adding a line break, when adding the item to the listbox, the line that adds the item is:

lstAlarm.Items.Add(TimeText & " " & dtDate.Text & " " & txtDetails.Text)

And i cant see anything on the propertys list for the text box that would add the line break.

Could you expand on your last comment please.

Many thanks
Hassan
 
Yes, but when you read in the file when app start you:
lstAlarm.Items.Add(srReader.ReadLine() & ControlChars.CrLf)
 
Thanks John your a star

I ma new to all this and wouldnt have twigged that that was the problem.:)

Many thanks

Hassan

PS Any coldfusion problems dont hesitate to ask
 
Back
Top