473,624 Members | 2,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

writing text to text files in vb. need help

hello all,
I've already posted a thread with the same problem but
couldn't satisfactory answer. Let's come to the point.

I can write some text to a text file with WriteAllText method. How can I
start new lines? Example, c:\test.txt is a file, then:

"This text should be written in 1st line of c:\test.txt"
"This text should be written in 2nd line of c:\test.txt"

Please write a that demonstrate the above task.

bye


Feb 21 '07 #1
3 1363
Dim MyLine as string
MyLine = "this is line 1" & vbcrlf
however you do append this line to your open text file, next
Myline = "this is line 2" & vbcrlf
however you do append this line to your open text file, next
and so on
HTH
"johnabraham101 " <jo************ @discussions.mi crosoft.comwrot e in message
news:56******** *************** ***********@mic rosoft.com...
hello all,
I've already posted a thread with the same problem but
couldn't satisfactory answer. Let's come to the point.

I can write some text to a text file with WriteAllText method. How can I
start new lines? Example, c:\test.txt is a file, then:

"This text should be written in 1st line of c:\test.txt"
"This text should be written in 2nd line of c:\test.txt"

Please write a that demonstrate the above task.

bye


Feb 21 '07 #2
"johnabraham101 " <jo************ @discussions.mi crosoft.comschr ieb
hello all,
I've already posted a thread with the same problem
but couldn't satisfactory answer. Let's come to the point.

I can write some text to a text file with WriteAllText method. How
can I start new lines? Example, c:\test.txt is a file, then:

"This text should be written in 1st line of c:\test.txt"
"This text should be written in 2nd line of c:\test.txt"

Please write a that demonstrate the above task.

bye

http://msdn2.microsoft.com/en-us/library/k3352a4t.aspx

Especially, if "new lines" means appending to a file:
http://msdn2.microsoft.com/en-us/library/3zc0w663.aspx

Also:
http://msdn2.microsoft.com/en-us/lib...b6(VS.71).aspx
Armin
Feb 21 '07 #3
johnabraham101 wrote:
I've already posted a thread with the same problem but
couldn't satisfactory answer. Let's come to the point.

I can write some text to a text file with WriteAllText method.
Short answer - Environment.New Line will add a line break into your file.

Longer answer -

WriteAllText() is what I call a "convenienc e method"; it wraps up lots
of other stuff and, so long as it does everything the way you want, all
well and good.
However, I suspect you're reaching a point where it's /not quite/
fitting your requirements any more and you need something else.

Here's another way ...

Dim sw as New StreamWriter( "file", False )

sw.WriteLine( "This text should be written in 1st line of c:\test.txt" )
sw.WriteLine( "This text should be written in 2nd line of c:\test.txt" )

sw.Close()

The StreamWriter class sports other useful methods that may help you in
your file creation as well, for example:

Dim sw as New StreamWriter( "file", False )

For iSub as Integer = 1 to 10
sw.Write( "Line " )
sw.Write( iSub.ToString() )
sw.WriteLine( " of 10" )
Next
sw.Close()

HTH,
Phill W.
Feb 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4015
by: George Stout | last post by:
First off I do not know alot about writing queries to an Access Database from an ASP page. This is why I need help. I have an Events database for 6 colleges in our metro area. On the homepage I have to display the next event for each college. That would give me 6 events listed on the page. I have been trying to figure out how to write a query statement in my ASP page to select just the most current event from each college. I have not had...
4
555
by: Simon | last post by:
Hi all, I have a process, where I take a dataset from an SQL call, and need to write an XML file from that dataset. The data set can contain 10's of tables, each with 100's of rows, and I have no way of knowing what the tables are, or what they contain. I am currently using the Dataset.WriteXML method passing an XMLWriter.
16
2197
by: iwdu15 | last post by:
how can i open a file i saved and place the info into different text boxes?
12
3753
by: Chris Springer | last post by:
I'd like to get some feedback on the issue of storing data out to disk and where to store it. I've never been in a production environment in programming so you'll have to bear with me... My question is about storing data in a database. Yes I understand that you can link to a database in your program and read and write to the database etc etc. Well, that's all find and dandy but what if the person you're writing the application for...
5
2167
by: Alan Searle | last post by:
I am exporting ms-access data to XML files. This works fine. However, I need to insert one line at the top of each exported file (i.e. a reference to the XSL file) and am having a problem with this. First I did the following: Export the XML file (using standard XML export) and then read the file (line by line) and writing it out (together with the required extra line) to a new file.
3
18958
by: nicolasg | last post by:
Hi, I'm trying to open a file (any file) in binary mode and save it inside a new text file. After that I want to read the source from the text file and save it back to the disk with its original form. The problem is tha the binary source that I extract from the text file seems to be diferent from the source I saved. Here is my code: 1) handle=file('image.gif','rb')
6
5259
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
1
1566
by: pablo.erba | last post by:
Hi Everyone, I´m new to this group, I´m trying to write a text files adding content from a text column (more than 8000 characters), I found code how to write files and it works but i have the problem when added the text column to the body of the file. any idea? tip? thanks in advance! Pablo.
0
8685
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8631
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8490
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.