How to add something at the end of a text file

  • Thread starter Thread starter Mota
  • Start date Start date
M

Mota

Hi;
I have a text file prepared by this code:

Open [FilePathAndName.txt] for Output As #1
Print #1,[something]
....
close #1

In another process and to complete this file i have to add </Y> at the
bottom of the file.I mean after closing the file.How to do that without
clearing the pre-written data in file?
Thank you for your help.
 
You can't add it after closing the file, but you can add it to what you are
writting to the file:
Print #1,[something] & "</y>"
 
In the other process you can reopen the file for append like this:

Open [FilePathAndName.txt] For Append Shared As #1
Print #1, "</y>"
Close #1

but better code would be:

Dim f As Long
f = FreeFile
Open [FilePathAndName.txt] For Append Shared As #f
Print #f, "</y>"
Close #f

FreeFile assures you get a unused filehandle
 
Its just what im looking for.But,wanna know why i have to use Shared after
Append?Is it arbitrary?
Thank you for your solution.

Ron Weiner said:
In the other process you can reopen the file for append like this:

Open [FilePathAndName.txt] For Append Shared As #1
Print #1, "</y>"
Close #1

but better code would be:

Dim f As Long
f = FreeFile
Open [FilePathAndName.txt] For Append Shared As #f
Print #f, "</y>"
Close #f

FreeFile assures you get a unused filehandle

--
Ron W
www.WorksRite.com
Mota said:
Hi;
I have a text file prepared by this code:

Open [FilePathAndName.txt] for Output As #1
Print #1,[something]
...
close #1

In another process and to complete this file i have to add </Y> at the
bottom of the file.I mean after closing the file.How to do that without
clearing the pre-written data in file?
Thank you for your help.
 
Yea for what I suspect you are doing, it is arbitrary. I have always used
it in case I need to have the same file open by more than one process at the
same time. For instance I am reading the file from one place and at the
same time I need to append more data from another place. Keeps you from
getting a "Permission Denied" or "File Sharing Error" error message. That's
also the reason for using FreeFile to get a file handle instead of trying to
keep track your hard coded ones.

--
Ron W
www.WorksRite.com
Mota said:
Its just what im looking for.But,wanna know why i have to use Shared after
Append?Is it arbitrary?
Thank you for your solution.

Ron Weiner said:
In the other process you can reopen the file for append like this:

Open [FilePathAndName.txt] For Append Shared As #1
Print #1, "</y>"
Close #1

but better code would be:

Dim f As Long
f = FreeFile
Open [FilePathAndName.txt] For Append Shared As #f
Print #f, "</y>"
Close #f

FreeFile assures you get a unused filehandle

--
Ron W
www.WorksRite.com
Mota said:
Hi;
I have a text file prepared by this code:

Open [FilePathAndName.txt] for Output As #1
Print #1,[something]
...
close #1

In another process and to complete this file i have to add </Y> at the
bottom of the file.I mean after closing the file.How to do that without
clearing the pre-written data in file?
Thank you for your help.
 
Thank you

Ron Weiner said:
Yea for what I suspect you are doing, it is arbitrary. I have always used
it in case I need to have the same file open by more than one process at
the
same time. For instance I am reading the file from one place and at the
same time I need to append more data from another place. Keeps you from
getting a "Permission Denied" or "File Sharing Error" error message.
That's
also the reason for using FreeFile to get a file handle instead of trying
to
keep track your hard coded ones.

--
Ron W
www.WorksRite.com
Mota said:
Its just what im looking for.But,wanna know why i have to use Shared
after
Append?Is it arbitrary?
Thank you for your solution.

Ron Weiner said:
In the other process you can reopen the file for append like this:

Open [FilePathAndName.txt] For Append Shared As #1
Print #1, "</y>"
Close #1

but better code would be:

Dim f As Long
f = FreeFile
Open [FilePathAndName.txt] For Append Shared As #f
Print #f, "</y>"
Close #f

FreeFile assures you get a unused filehandle

--
Ron W
www.WorksRite.com
Hi;
I have a text file prepared by this code:

Open [FilePathAndName.txt] for Output As #1
Print #1,[something]
...
close #1

In another process and to complete this file i have to add </Y> at the
bottom of the file.I mean after closing the file.How to do that
without
clearing the pre-written data in file?
Thank you for your help.
 
Back
Top