shortening my sequencing records without writing each record
#11
To replace say record 16 in a sequential file, you have to set up a temporary file, write all the old data to it, except for the 16th record, which would be replaced with the new data. then kill the old file and name the temporary file as the old file.

Caution: running this code will overwrite any file you already have named myfile.dat and tmp.tmp.

Code: (Select All)
target = 16: replace$ = "My new data."
OPEN "MYFILE.dat" FOR INPUT AS #1
OPEN "tmp.tmp" for OUTPUT AS #2
DO UNTIL EOF(1)
i = i + 1
LINE INPUT #1, a$
IF i = target then a$ = replace$
PRINT #2, a$
LOOP
CLOSE #1, #2
KILL "MYFILE.dat
NAME "tmp.tmp" as "MYFILE.dat"

Of course to get this code to work, you'd have to make and fill the "MYFILE.dat" file.

Pete
Reply


Messages In This Thread
RE: shortening my sequencing records without writing each record - by Pete - 10-02-2022, 02:20 AM



Users browsing this thread: 8 Guest(s)