Re: Determine if any files were left open
From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 08/04/04
- Next message: Randy Birch: "Re: Another IP address question (how to get IP address of remote computer)"
- Previous message: Jeff Johnson [MVP: VB]: "Re: Access control of a mdi child from mdi child"
- In reply to: jim: "Determine if any files were left open"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 4 Aug 2004 12:06:16 -0400
Just use the Close statement without a filenumber. This closes all open
files.
-- Randy Birch MVP Visual Basic http://vbnet.mvps.org/ Please respond only to the newsgroups so all can benefit. "jim" <edasich@nooo.spam.yahoo.com> wrote in message news:#ZqTzAaeEHA.712@TK2MSFTNGP09.phx.gbl... : If there a simpler method to determine if I left open any files? : : For example, my application opens, processes AND closes many files. However : I want to be sure that when the application closes I did not accidently : leave open a file and not close it properly. : : I am using the rather inelegant method shown below that iterates though the : maximum number of file numbers I expect, tries to open the file number and : traps any open error: : : thanks : : Private Function AnyFileOpen() As Integer : : 'Purpose: Determine if any file is open. If so return the file number : of the first open file : ' Place function in loop until AnyFileOpen() returns 0. : : Dim k As Integer : On Error GoTo OpenError : : AnyFileOpen = 0 : For k = 1 To 99 : Open "F" & Format$(k, "000") For Output As #k : Close #k : Next k : : Exit Function : : OpenError: : If Err.Number > 0 Then 'Err=55 for already open. : AnyFileOpen = k : Debug.Print k, Err.Number, Err.Description : Exit Function : End If : : End Function : :
- Next message: Randy Birch: "Re: Another IP address question (how to get IP address of remote computer)"
- Previous message: Jeff Johnson [MVP: VB]: "Re: Access control of a mdi child from mdi child"
- In reply to: jim: "Determine if any files were left open"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|