CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 3 of 3

Thread: Closing file problems

  1. #1
    Join Date
    Oct 2003
    The Dutch Mountains

    Closing file problems

    Hey Guys,
    I open a file for "Input As" and then close it.
    After that open the same file for "Append As"but then I got an error, that the file is still in use or allready open.

    Is there a solution to close the file quicker?
    This is what I use now:

    f = "C:\test.dat"
    i = FreeFile
    Open f For Input As #i
    Close #i

    f= "C:\test.dat"
    i2 = FreeFile
    Open f For Append As #i2
    Close #i2

    Thanks allready
    Give up your guns and face the law!!

  2. #2
    Join Date
    Jan 2004
    San Diego

    Re: Closing file problems

    Set the initial Open command to be shared access. This way it shouldn't matter if the file is already opened you will still be able to do your append operation later.
    Open f For Input Shared As #i
    Death is life's special way of telling you you're fired.

    For I do not seek to understand in order to believe, but I believe in order to understand. For I believe this: unless I believe, I will not understand. - Anselm of Canterbury (10331109)

  3. #3
    Join Date
    Dec 2001

    Re: Closing file problems

    You can Open for Append when creating files too, so if you will be opening the file again immediately afterward anyway, you might just open it once with Append.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)