Add 1 to Text File

S

Stephen Lynch

I am looking to open a text file, input each line and rewite the line adding
a file name plus 1. For example:

Original text file
John, Doe, Chicago
Jane, Doe, Chicago

What I want
John, Doe, Chicago, 1
Jane, Doe, Chicago, 2


Also, I am refering to a file name that I have declared in another function
as a string so I am not sure if I need to change that. But here's where I
am, just learning.


Function Add1toEndofFile(FileID As String)

Dim strOneLine As String
Dim strCounter As Integer
FileID = FreeFile
Open FileID For Input As #FileID
Do Until EOF(FileID)
Line Input #FileID, strOneLine
Print strOneLine, FileID &" "& strCounter
strCounter = strCounter + 1
Loop
Close #FileID

But I am getting all kinds of errors. What I want to do is open the same
file and just add the filename and counter line to the end of each line.

Thanks for any assistance.


End Function
 
J

John Spencer

I THINK you might be better off if you open a second file as the
destination and write to it. Once you have finished, you can delete the
source file (if you wish) and rename the destination file with the name
of the source file.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 
D

dch3

Take a look at the FileSystemObject - open Help and search on the temr. It
provides access to the neccessary methods to read and write to text files and
will allow you to read a file line by line.
 

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