output to the same line in a Text file?

B

Bernard

hi there
How do I output to the same position in a Text file everytime? I want to
dump data for a given Date so I'd like to put it in the same row for that
Date everytime, and so overwrite the existing data in that row?

I'm using the following command:

Write #3, logfactor(dateline, 1), logfactor(dateline, 2),
logfactor(dateline, 3)

'where dateline is today's date in Excel date code e.g. 40010

I want to be able to overwrite the existing data for line 40010 in my text
file, and replace it with new data.

Hope that it clear!!!!
thank you
Bernard.
 
J

JLatham

If, and it's probably a big if, each line in the text file is always exactly
the same length, you could open the file for Binary access, read through it
until you find the beginning of the line you need and replace that line with
the new data.

Barring that, the easiest way is probably to open the existing file for
input, open a second file for output, then
read a line from it,
test if it is the line your want
if not the line you want, write it to the 2nd file
if it is the line you want, write the new data to the 2nd file
and then just read and write from 1st to 2nd to the end of the 1st.
After that you can KILL the 1st file and name the 2nd one with the original
file name.
 
B

Bernard

Thanks J.
No the lines are different lengths but good thinking. Your idea for using
two files is also good, and workable.
I thought (from recollection of a programming course a long time ago, that
there was a command for output to a record position, but maybe not.
thanks
Bernard.
 

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