themroc
asked on
how to ad one line to the end of a sequentiell file
I have to add one line to an existing sequentiell line,
so if the file looks as follows
line1
line2
line3
end
then I have to write
text line 4
behind line3
How do I do it with the
PRINT statement
can anyone give some coding??
so if the file looks as follows
line1
line2
line3
end
then I have to write
text line 4
behind line3
How do I do it with the
PRINT statement
can anyone give some coding??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
my point, EXACTLY.
AW
AW
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi,
forgot to say that to open it for append you should do like this:
Open "your file name" For Append Access Write As #1
Bye,
Max
forgot to say that to open it for append you should do like this:
Open "your file name" For Append Access Write As #1
Bye,
Max
MaxPol:
because:
>If you open the file for append, then you could easily use
>print #1,"your last line" & vbcrlf
will end up with:
line1
line2
line3
end
line4
id 'end' is REALLY present as the last record in the original file. If that is what is desired then OK, but otherwise the other comments apply.
AW
because:
>If you open the file for append, then you could easily use
>print #1,"your last line" & vbcrlf
will end up with:
line1
line2
line3
end
line4
id 'end' is REALLY present as the last record in the original file. If that is what is desired then OK, but otherwise the other comments apply.
AW
Ops,
then you could try to find the file size (use the FileLen command),
now open the file in random mode read write , and read data at the countrary (read byte by byte with reclen=8
if after end you have a vbcrlf, then do like this
Dim sString as string * 8
Dim lFilePos as long
lFilePos=FileLen("yourfile namehere"
get #1,lFilePos-8,sString ' this will read the vbcrlf & "end" & vbcrlf if after end you have vbcrlf if not, change the reclen=6 and sString to string *6 and lFilePos-6
Now you are in the right place,
do a Print#1, "the new line" & vbcrlf & "end" ' if required add vbcrlf
Bye,
Max
then you could try to find the file size (use the FileLen command),
now open the file in random mode read write , and read data at the countrary (read byte by byte with reclen=8
if after end you have a vbcrlf, then do like this
Dim sString as string * 8
Dim lFilePos as long
lFilePos=FileLen("yourfile
get #1,lFilePos-8,sString ' this will read the vbcrlf & "end" & vbcrlf if after end you have vbcrlf if not, change the reclen=6 and sString to string *6 and lFilePos-6
Now you are in the right place,
do a Print#1, "the new line" & vbcrlf & "end" ' if required add vbcrlf
Bye,
Max
sub apptext(filename as string, stext as string)
dim i as integer,buff as string
i=freefile
open filename for input as #i
buff=input(lof(i),1)
close#i
open filename for output as #i
print#i,replace(buff,"end" ,stext,,vb textcompar e)
print #i,"end"
close#i
end sub
dim i as integer,buff as string
i=freefile
open filename for input as #i
buff=input(lof(i),1)
close#i
open filename for output as #i
print#i,replace(buff,"end"
print #i,"end"
close#i
end sub
ASKER
thanks for the contributions, i am sorry that I could not reply earlier to say that the first answer was alresdy what I was after, but the additional comments were very helpfull
:}
:}
well, if you finally use the first comment, take in mind the comments from Arthur_Wood.
1) Read the entire file into memory then write it back out adding your line before the end.
2) Read the file and write a second file as you go. Then delete the original and rename the second file to the first.
Idle_Mind