Link to home
Start Free TrialLog in
Avatar of Optamis
Optamis

asked on

Writing to a text file

This might be an easy question but I'm having problems writing to a text file in visual basic .net 2005.  The old visual basic syntax of " Open "file" for output as #1" does not seem to work at all.  This is not really the problem though, my problem lies in just getting the syntax right to write to a simple text file created using:

Dim result As System.IO.TextWriter = System.IO.File.CreateText("C:\Documents and Settings\astairs\Desktop\result.txt")

Any help is greatly appreciated!!
ASKER CERTIFIED SOLUTION
Avatar of List244
List244

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Optamis
Optamis

ASKER

I guess perhaps I should search before I haul off and ask a question...  Very helpful though, fixed my problem 100%.  I do have one more question though, what's the syntax for starting a new line and new page when writing to a text file?
I believe the following would all give you results for new line:

Chr(13) + Chr(10)
file.WriteLine()
ChrW(13) + ChrW(10)
Environment.NewLine()

I do not know exactly what you mean by a new page though.
Also, in the future, you may be better off posting your questions here:

https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/
Avatar of Optamis

ASKER

Thanks List244,  Unfortunatly

Chr(13) + Chr(10)
file.WriteLine()
ChrW(13) + ChrW(10)
Environment.NewLine()

isn't working for me to get a new line.  All I need to do is after  the Writeline is start a newline.  Also, what I mean but a new page is that after so many writes or when the page is full it will insert the page number and start a new page.  Any ideas?

Thanks again!!
Avatar of Optamis

ASKER

I figured it all out, thanks for the help.  Without your guidance I wouldn't have the working writelines.  Thanks List244.
Optamis, I should have been more clear with my first post, what I meant was you could use the chr and environment options
as string appends to add new lines.  The file.WriteLine() would write a line byitself.  They were just many options on how
you could do it.

However, I am glad you got it all worked out.