Click to See Complete Forum and Search --> : End-of-file in VB
Pasi Salminen
July 22nd, 1999, 03:55 AM
Hello!
How can I set the end-of-file mark with VB5?
I use a data-file with my program and when user deletes some records I should delete them from
the data-file and decrease the data-file length.
Thanks!
Pasi Salminen
pasisalminen@hotmail.com
freek
July 22nd, 1999, 04:56 AM
what do you mean by a data-file, an access file or a text file (in case of a text file, how do you open it)
Pasi Salminen
July 22nd, 1999, 05:16 AM
Hi!
I'm using text file and I open it with Open method in VB. I can open the text file in mode which is needed to set end-of-file mark.
Pasi Salminen
pasisalminen@hotmail.com
freek
July 22nd, 1999, 05:51 AM
if you open the text file like this
open filename for input as #1
you can use
do until EOF(1)
something
loop
if you open it binary you have to calculate how many records there are in the file
to do that, you have to do something like this
size-of-file / size-of-record
If you want I can send you an example of a small application that uses text files
Pasi Salminen
July 22nd, 1999, 06:08 AM
I know how to write to the file, but how can I "shorten" the file.
In my program recordlength is 14 bytes and if there are for example 5 records the file-length is 70 bytes. If user deletes one record then I should "shorten" the file to 56 bytes (=70-14).
How can I do that? (Without deleting the hole file and creating new)
Pasi Salminen
pasisalminen@hotmail.com
Crazy D
July 22nd, 1999, 11:05 AM
What do you do if the user deletes say record 2? do you move the rest of the records to fill the gap? (if you do that, you can just as easy create the new file..)
Pasi Salminen
July 23rd, 1999, 12:51 AM
Yes, I move the rest of the recors backwards.
I have solved the problem with API call to the SetEndOfFile function.
Thanks to all about advice!
Pasi Salminen
pasisalminen@hotmail.com
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.