Solved

Writing to a text file

Posted on 2006-06-16
7
168 Views
Last Modified: 2010-04-30
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!!
0
Comment
Question by:Optamis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 8

Accepted Solution

by:
List244 earned 500 total points
ID: 16920715
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21007855.html?query=vb.net+file+write&clearTAFilter=true

Dim file As New System.IO.StreamWriter("c:\test.txt", False) ' if the file exist and Append is False, The file is overwritten
file.WriteLine(content)
file.Close()
0
 

Author Comment

by:Optamis
ID: 16921048
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?
0
 
LVL 8

Expert Comment

by:List244
ID: 16921122
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:List244
ID: 16921127
Also, in the future, you may be better off posting your questions here:

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/
0
 

Author Comment

by:Optamis
ID: 16921176
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!!
0
 

Author Comment

by:Optamis
ID: 16921303
I figured it all out, thanks for the help.  Without your guidance I wouldn't have the working writelines.  Thanks List244.
0
 
LVL 8

Expert Comment

by:List244
ID: 16921399
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.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question