PC Review


Reply
Thread Tools Rate Thread

Add 1 to Text File

 
 
Stephen Lynch
Guest
Posts: n/a
 
      27th Jul 2008
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



 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      27th Jul 2008
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
'====================================================


Stephen Lynch wrote:
> 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
>
>
>

 
Reply With Quote
 
dch3
Guest
Posts: n/a
 
      27th Jul 2008
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.

"Stephen Lynch" wrote:

> 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
>
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
export datagridview to text file and import text file to sql servertable on the fly TG Microsoft VB .NET 2 17th Jul 2008 03:01 PM
Read Text File and split them to individual text file Krish Microsoft C# .NET 3 21st Oct 2005 03:49 AM
how to export a text file to ansys and text file to structure Nagendra Singh Dhakar via AccessMonster.com Microsoft Access VBA Modules 1 2nd Apr 2005 07:20 PM
Excel VBA - open text file, replace text, save file? Cybert Microsoft Excel Programming 2 2nd Oct 2004 01:05 AM
importing text file, removing data and outputting new text file Pal Microsoft Excel Programming 8 27th Feb 2004 08:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:21 PM.