• Welcome to Valhalla Legends Archive.
 

Question: "File Already Open" Error

Started by DarkOne, February 27, 2004, 05:42 PM

Previous topic - Next topic

DarkOne

I've tried countless methods to try and eliminate this problem such as using the FreeFile function to retrieve available file handles and still got this error.

I have looked over and over all my procedures for opening and closing files and I have closed every file that I originally opened. I have also tried setting procedures to load/save settings from files I am working with sequentially and I am still getting the error.

Any help would be appreciated.

Tasha

#1
DarkOne
Newbie

Right there says it all Dan :P

And i've read your post like 3 times, wtf are you talking about? -.-

EDIT: :P Nevermind I see what you're talking about. You're trying to open the file, and it says the file is all ready running, but like it doesn't appear anywhere? If that's the case just control alt delete and find the filename you're trying to open, close that and it should work.

If you're talking about the same thing I had problems with last week about opening like most of my programs like aim, winamp, starcraft, I found out it was a virus though and removed it, dunno if it's the same problem though :)

Stealth

Make sure your code doesn't try to open any files that are already open within your program. ie:


Open fileX.txt for Input as #f
'do stuff
call OpenNewFile()
Close #f

'in OpenNewFile()
Open fileX.txt for input as #otherf 'this will cause the error, even though
'the file has a new FreeFile number, you have it open already in the calling procedure.
- Stealth
Author of StealthBot

Newby

#3
Here is some coding that helps me.



Dim FNUM as Integer
FNUM = FreeFile()

Open App.Path & "\Boobies.txt" for Output As #FNUM
   Print #FNUM, "( . ) ( . )"
Close #FNUM



Try that.
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Dyndrilliac

Quote from: Newby on February 27, 2004, 06:38 PM
Here is some coding that helps me.



Dim FNUM as Integer
FNUM = FreeFile()

Open App.Path & "\Boobies.txt" for Output As #FNUM
   Print #FNUM, "( . ) ( . )"
Close #FNUM



Try that.

You don't need the App.Path & "\Boobies.xt", as the program assumes if you only have the file name it's the same directory as the app anyway, so "Boobies.txt." would work just fine.
Quote from: Edsger W. DijkstraIt is practically impossible to teach good programming to students that have had a prior exposure to BASIC; as potential programmers they are mentally mutilated beyond hope of regeneration.

Adron

Quote from: Dyndrilliac on February 27, 2004, 07:11 PM
You don't need the App.Path & "\Boobies.xt", as the program assumes if you only have the file name it's the same directory as the app anyway, so "Boobies.txt." would work just fine.

I think it will assume the current directory, which may or may not be the same as the application directory.

K

Quote from: Adron on February 27, 2004, 07:14 PM
Quote from: Dyndrilliac on February 27, 2004, 07:11 PM
You don't need the App.Path & "\Boobies.xt", as the program assumes if you only have the file name it's the same directory as the app anyway, so "Boobies.txt." would work just fine.

I think it will assume the current directory, which may or may not be the same as the application directory.

Correct - for example, if you start a program from a shortcut, the working directory is often not the application directory.

Newby

Quote from: Dyndrilliac on February 27, 2004, 07:11 PM
Quote from: Newby on February 27, 2004, 06:38 PM
Here is some coding that helps me.



Dim FNUM as Integer
FNUM = FreeFile()

Open App.Path & "\Boobies.txt" for Output As #FNUM
   Print #FNUM, "( . ) ( . )"
Close #FNUM



Try that.

You don't need the App.Path & "\Boobies.xt", as the program assumes if you only have the file name it's the same directory as the app anyway, so "Boobies.txt." would work just fine.

Hehe, I did not know that. I've always used App.Path & Filename. Thanks! :)
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

Spht

Quote from: Newby on February 27, 2004, 07:53 PM
Hehe, I did not know that. I've always used App.Path & Filename. Thanks! :)

You may want to read the posts following that one...

DarkOne

#9
Stealth, I have ensured that is not happening. Like I said, I even tried opening the files sequentially so one file is being opened/closed in order to prevent two files to open on the same file handle.

Also, Newby I have tried your method and still no sucess.

I'll try to figure it out, there 'must' be something I have overlooked obviously.

I just recently tried assigned unique file handle numbers to each and every file open/close operation in my program and I noticed that I always get an error on the LAST file handle. If I increase the file handle number, the same thing occurs, it says that file is already open.

Any idea?

o.OV

#10
Here is a possible scenario:

You "Open" a file.
You process a few lines..
and somewhere between "Open" and "Close"..
you have EXIT/GOTO setup that skips "Close".

that might be the cause of your problem  :-\
Check your coding for anything resembling that scenario..

You can give it a TEMPORARY fix
by placing "Close" before every "Open".

Add-On:

Give us the code where it errors at.
It would be easier for us to deduce the problem
if we had actual code to examine.
If the facts don't fit the theory, change the facts. - Albert Einstein

Eric

Quote
You can give it a TEMPORARY fix
by placing "Close" before every "Open".
If the file was already closed it would just give you another error.

DarkOne

#12
Here I am creating files required to store user's settings and in this case for the sake of debugging, I am loading my 'LoadFilters' function, shown below this snippet.


Private Sub Form_Load()
   Open "Config.txt" For Append As #1
   Close #1
   Open "UserFilters.txt" For Append As #1
   Close #1
   Open "TalkFilters.txt" For Append As #1
   Close #1
   
   'LoadConfig
   LoadFilters
   .
   .
   .
End Sub


Here is the 'LoadFilters' function:

Public Function LoadFilters()
   Dim line As String
   
   Open "UserFilters.txt" For Input As #1
       Do While Not EOF(1)
           Input #1, line
           frmFilters.lstUsers.ListItems.Add , , line
       Loop
   Close #1
   
   Open "TalkFilters.txt" For Input As #1
       Do While Not EOF(1)
           Input #1, line
           frmFilters.lstText.ListItems.Add , , line
       Loop
   Close #1
End Function


When calling the LoadFilters function, I get an error reporting that the "file already open" on line #3 of this function, "Open "UserFilters.txt" For Input As #1".

Newby

Quote from: LoRd[nK] on February 28, 2004, 12:43 AM
Quote
You can give it a TEMPORARY fix
by placing "Close" before every "Open".
If the file was already closed it would just give you another error.

No, that's untrue.
- Newby

Quote[17:32:45] * xar sets mode: -oooooooooo algorithm ban chris cipher newby stdio TehUser tnarongi|away vursed warz
[17:32:54] * xar sets mode: +o newby
[17:32:58] <xar> new rule
[17:33:02] <xar> me and newby rule all

Quote<TehUser> Man, I can't get Xorg to work properly.  This sucks.
<torque> you should probably kill yourself
<TehUser> I think I will.  Thanks, torque.

o.OV

#14
Well Dark.. the code you pasted runs fine.

I started a new project and pasted that code in
and voided out the object items..

Ran it with items in file and without items in file.

It ran fine.

"While Not" should be changed to "Until"
"Public Function LoadFilters()" should be changed to "Public Sub LoadFilters()"

Let's get this straight..
It errors at.. "Open "UserFilters.txt" For Input As #1" ?
I'll make an assumption in your actual code
you have it as:


LoadConfig

and not


'LoadConfig

If so.. then the problem is somewhere in LoadConfig.
If the facts don't fit the theory, change the facts. - Albert Einstein