Results 1 to 11 of 11

Thread: File CLOSE does not CLOSE file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    Unhappy

    My application reads a txt file using OPEN / CLOSE. Even after the application is ended, the file is in a state that will not allow the Delete function of Windows Explorer to work. What is returned is this message

    "Error Deleting File Cannot delete tempea: Access is denied
    Make sure the disk is not full or write-protected
    and that the file is not currently in use."

    If I reboot my PC, then I can delete the file with Windows Explorer.

    What can I do within my VB program to make this file available for normal
    use??


    ***********
    ***********
    I found a chunk of code to test whether a file was open or closed. Put it in at the end of my application and when found the file open, I used the CLOSE #5 to close the file in question. I had called the code chunk a second time to see if the file was open or closed. IT IS STILL OPEN!!

    That is why I get the problem stated above.

    How can I close the file? Or figure out why it is still OPEN??

  2. #2
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Try
    Code:
    Close #filenumber
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  3. #3

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Close #1 closes #1 file
    Close will close all files

    Should use freefile when opening and closing files cause
    that way vb looks after the numbers.

    Dim intNum as Integer
    intNum = Freefile

    Open myfile for input as intNum
    'bla bla
    Close #intNum

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    OPEN & CLOSE code

    Here is the code I use for opening and closing....

    OPEN***********

    Open txtProjectFile For Input As #5



    CLOSE**********

    If IsFileAlreadyOpen(gtProjectPath & "\TEMP" & gtUserID & ".exp") Then
    MsgBox "File open!"
    Close #5
    Else
    MsgBox "File not open!"
    End If

    If IsFileAlreadyOpen(gtProjectPath & "\TEMP" & gtUserID & ".exp") Then
    MsgBox "File open!"
    Close #5
    Else
    MsgBox "File not open!"
    End If

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    the if statement is not working properly.
    you do not close it in the else part so that means the if it is open is not working properly.
    To test this theory, put Close # 5 in else part of your statement as well and it should be closed.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    I assume that your open and close code is not in the same procedure. If that is the case, your code is failing since the #5's you are using are local to the procedures in which they appear and are not the same. Create a form-level or module-level variable with code like

    Public m_MyFile As Integer

    Then in your Open routine

    Open txtProjectFile For Input As m_MyFile

    and in your close routine

    Close m_MyFile

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    Thanks, but that does not solve the problem

    I tried the global variable, giPTR5 initialized to a 5 and replaced all of my occurances of #5 with #giPTR5. That did not make any difference. Still have the problem.

    I added the additional Close #giPTR5 to the if logic, but it also had no effect??


  9. #9

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    Question AH HAH!! Another piece

    I changed the location of my file from my H:\ (network drive) to a local D:\ PC drive and my application works correctly.


    Sooooo, something about OPEN / CLOSE on a network drive is giving my program fits. Any clues about this aspect??

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    Thumbs down Mystery continues

    I moved my app to a faster machine(500mH). Now the app will not work on the local D:\ drive. It behaves exactly like the slower PC(166mH) with the network connection. So, it must be something about Winword being closed at the same time I am trying to close the text file. I will rearrange my code and let the text file close first and see if that makes a difference.

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Posts
    16

    Smile Problem is solved!!

    By closing my text file before the user closes word, the text file is closed and can be deleted with Windows Explorer.

    Not sure why the sequence of opening word doc, then a text file, closing word, then closing the text file does create a problem.

    But, opening a word doc, opening a text file, closing the text file, then closing word does work without problems.


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