Inserting line breaks in text file?

B

Brett

I'm writing something similar to this into a text file:

txtfileError.WriteLine(CurrentDateTime(1) & " Error in Sub Sub1()" & idvar &
Chr(10) & Chr(13) & ex.Message)
txtfileError.WriteLine()

Instead of line breaks, I see two boxes. Everything runs together. There
is a double line break where the WriteLine() is. How do I place a single
line break in the text file?

Thanks,
Brett
 
H

Herfried K. Wagner [MVP]

Brett said:
I'm writing something similar to this into a text file:

txtfileError.WriteLine(CurrentDateTime(1) & " Error in Sub Sub1()" & idvar
& Chr(10) & Chr(13) & ex.Message)
txtfileError.WriteLine()

Instead of line breaks, I see two boxes. Everything runs together. There
is a double line break where the WriteLine() is. How do I place a single
line break in the text file?

'WriteLine' will add a single line break. Altneratively you can include
'ControlChars.NewLine' in the string you write to the file.
 
J

Jim Hughes

Chr(10) & Chr(13) should read Chr(13) & Chr(10)

The Carriage Return (13) comes before the Line Feed (10) vbCrLf

Even better use is to use Environment.NewLine or break it up into multiple
writes.

txtfileError.WriteLine(CurrentDateTime(1) & " Error in Sub Sub1()" & idvar)
txtfileError.WriteLine( ex.Message)
txtfileError.WriteLine()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top