CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 1999
    Posts
    16

    End-of-file in VB

    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
    [email protected]



  2. #2
    Join Date
    Jul 1999
    Posts
    104

    Re: End-of-file in VB

    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)


  3. #3
    Join Date
    Jun 1999
    Posts
    16

    Re: End-of-file in VB

    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
    [email protected]


  4. #4
    Join Date
    Jul 1999
    Posts
    104

    Re: End-of-file in VB

    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


  5. #5
    Join Date
    Jun 1999
    Posts
    16

    Re: End-of-file in VB

    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
    [email protected]


  6. #6
    Join Date
    Apr 1999
    Location
    Rotterdam, Netherlands
    Posts
    278

    Re: End-of-file in VB

    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..)


  7. #7
    Join Date
    Jun 1999
    Posts
    16

    Re: End-of-file in VB

    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
    [email protected]



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured