|
-
Oct 10th, 2000, 12:34 PM
#1
Thread Starter
Junior Member
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??
-
Oct 10th, 2000, 12:40 PM
#2
Hyperactive Member
Visual Basic 6 SP4 on win98se
QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!
-
Oct 10th, 2000, 12:40 PM
#3
Please post the code you use to open and close the file.
-
Oct 10th, 2000, 12:42 PM
#4
_______
<?>
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
-
Oct 10th, 2000, 12:50 PM
#5
Thread Starter
Junior Member
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
-
Oct 10th, 2000, 01:02 PM
#6
_______
<?>
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
-
Oct 10th, 2000, 01:02 PM
#7
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
-
Oct 10th, 2000, 01:24 PM
#8
Thread Starter
Junior Member
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??
-
Oct 10th, 2000, 01:35 PM
#9
Thread Starter
Junior Member
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??
-
Oct 11th, 2000, 09:40 AM
#10
Thread Starter
Junior Member
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.
-
Oct 11th, 2000, 12:21 PM
#11
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|