Help Writing to a Text File

Hello
I am a novice developer so please don't hesitate to reply me coz I appreciate your help.
I am writing to a text file using a stream writer. When I use the Write Method, the text file looks like this:

<Value><Value><Value><Value><Value><Value>

and when I use the WriteLine method, the text file looks like this:

<Value>

<Value>

<Value>

But I want my text file to look like this so I can read values later:
<Value>
<Value>
<Value>

Any idea?

Thank You

[564 byte] By [Haitham.ElGhaareeb] at [2007-12-16]
# 1

I just did the following, and it worked fine:



Private Shared Sub WriteValues()
Using writer1 As StreamWriter = New StreamWriter("c:\test.txt")
Dim num1 As Integer
For num1 = 0 To 100
writer1.WriteLine(("Value: " & num1))
Next num1
End Using
End Sub

When you call WriteLine are you adding an extra end-of-line character?

DavidM.Kean at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2
First:
I really appreciate your reply sir, thank you very much.

Second:
I have tried the code you posted myself, and it worked really so fine as I wanted to, but when I pasted into my project, it didn't go as well as solely, so I think it would be a good idea to discuss the application and post my code:

I am developing an application that draws on the form certain shapes:
Line,Rectangle,and Circle.

I have a menu that have items for each shape, when the user chooses certain shape, the appropriate declarations are made, ex. in case line, two points are declared, incase ellipse:x,y,w,h

Then, a new entry is added to the public array of strings I have, in case line: I add a new entry of "Line", then p1.x , p1.y, and so on.

Incase the user decides to save, the array content is written to a text file, and here goes the problem.

I'm not so sure if all what I said relates to the problem in hand, but I thought discussing it will be fine.

'The add to array function I use
Public
Sub AddtoArray(ByVal St As String)
Dim ArrLen As Integer
ArrLen = PS.Length
ArrLen += 1
ReDim Preserve PS(ArrLen)
PS(ArrLen) = St
End Sub

'The Save File Function
Dim
fs As New System.IO.FileStream("C:\test.txt", IO.FileMode.Create)
Dim fw As New System.IO.StreamWriter(fs)
Dim Count As Integer = PS.Length
For i As Int16 = 0 To Count - 1 Step 1
fw.WriteLine(PS.GetValue(i))
Next
fw.Flush()
fw.Close()

You can try it Sir, Can you help me with this?

Thank You <Really> Anyway.

Haitham.ElGhaareeb at 2007-9-8 > top of Msdn Tech,Visual Basic,Visual Basic General...