Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about vbCrLf with a text file.

Status
Not open for further replies.

onedizzydevil

Programmer
Mar 24, 2001
103
US
First, let me state this sounds like a pretty remedial question but I have been stumped off and on for last two months and now it is time to ask.

I am dealing with text files the way that I am currently doing it is like this.

[tt]Dim strBody As New StringBuilder
strBody.Append("Thank you for your order.")
strBody.Append(vbCrLf, 1)
strBody.Append("The details of your order follow.")
strBody.Append(vbCrLf, 2)
strBody.Append("Bill To")
strBody.Append(vbCrLf, 1)
strBody.Append("-----------------------------")
strBody.Append(vbCrLf, 1)

If Not File.Exists(FilePath & FileName) Then
FileWriter = File.AppendText(FilePath & FileName)
FileWriter.Write(strBody.ToString)
FileWriter.Close()
Else
'...
End If
[/tt]


The problem is this. If I open the file in Notepad the vbCrLf cause a block character to show up. And this seems to work fine when sending an email. However, ASCII text file readers will not read the files the get stuck on the vbCrLf character.

Now when I looked at the file in HEX code the vbCrLf generates an 0D 0A which is mean Chr(13) & Chr(10).

Now if I make a text file in Notepad and I press Enter to get a new line I do not get a block character but a new line. Soooo.. I save this file and look at in HEX and the character that generates the new line are 0D 0A as well.

And the ASCII text file readers will read that file just fine. What the heck it going on????

HELLLLLLLLLLLLP! ME!

Thanks

-Wayne

Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Try:

Environment.NewLine

I know what you mean on those little blocks, and I'm pretty sure that the above does not put them in there, but I wouldn't swear to it.

-paul

penny.gif
penny.gif

The answer to getting answered -- faq855-2992
 
Hi there!
Take a look at System.IO.StreamWriter and its WriteLine.
Here's an example:
Code:
Dim fs As FileStream
Dim fl As String = Server.MapPath("test.txt")
fs = File.Open(fl, FileMode.Append, FileAccess.Write)
Dim sw As StreamWriter = New StreamWriter(fs)
sw.WriteLine("Line 1")
sw.WriteLine("Line 2")
sw.WriteLine()
sw.WriteLine("Line 4")
sw.WriteLine()
sw.WriteLine()
sw.WriteLine("Line 7")
sw.Close()
fs.Close()

I hope this helps!

[morning]
 
Just for follow up for future readers...

The Environment.NewLine did not work.

The filestream did work but I had to have two version of the code because it was being emailed and wrote to a text file (which would be automagically faxed out).

But it did work.

Wayne Sellars

"Programming, today is a race between software developers, striving to build bigger and better idiot-proof programs, and the Universe, trying to produce bigger and better idiots. So far, Universe 1 - Programmers 0."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top