Solved

Writing to text files

Posted on 2004-09-28
4
8,223 Views
Last Modified: 2012-08-14
Hello, Experts.  The code bellow writes 2 line to a text file.

open ("c:\document.txt") for output as #1
print #1, "A line of text"
print #1, "Another line of text"
close #1

How can I make the next time i add text to the file for the text to start on the third (first empty row) line?

Can somebody point me to a good VB/VBA text editing site, i need to write and read plain text and CSV text files.

Thanks
0
Comment
Question by:sublimation
[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
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
bingie earned 300 total points
ID: 12168918
open ("c:\document.txt") for append as #1
print #1, "A line of text"
print #1, "Another line of text"
close #1

Change "output" to "append" and it will append the file next time, otherwise it will over write any data in the file.
0
 
LVL 13

Assisted Solution

by:imarshad
imarshad earned 200 total points
ID: 12168992
Also you may like to have a look at a similar question that I asked.......I got a good Class Library code from sudhakar_koundinya....It is an absolutely brilliant Library for different functions for Text Files......
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21100341.html

Imran Arshad
0
 
LVL 13

Expert Comment

by:imarshad
ID: 12169036
You should add a Class Module in your code and then copy the whole code over there.......

Then you can use the following code......

Private Sub Command1_Click()
Dim o As New TextFile
Dim str As String
o.TextFilePath = "c:\a.txt"
o.WriteNewLine "A line of text"
o.WriteNewLine "Another line of text"
End Sub


with many other features as well........

Imran Arshad
0
 
LVL 9

Expert Comment

by:experts1
ID: 12437129
Try this modification to your code.

This method uses a subroutine to add(append) new text
to the file "document.txt".

Note:
The file is opened for "Append" in subroutine.
     
open ("c:\document.txt") for output as #1
print #1, "A line of text"
print #1, "Another line of text"
close #1

Call AddLine("Some new text")

Private Sub AddLine(ByVal newtext As String)
Open ("c:\document.txt") For Append As #1
  Print #1, newtext
Close #1
End Sub

The above method uses a subroutine to append new text
to the file "document.txt".

Have Fun!!
Experts1
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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 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