Re: Determine if any files were left open

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 08/04/04


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
:
: 


Relevant Pages

  • Re: Determine if any files were left open
    ... A better approach would be to design your app to eliminate the problem, ... > For example, my application opens, processes AND closes many files. ... > I am using the rather inelegant method shown below that iterates though ... > On Error GoTo OpenError ...
    (microsoft.public.vb.general.discussion)
  • Determine if any files were left open
    ... For example, my application opens, processes AND closes many files. ... of the first open file ... ' Place function in loop until AnyFileOpenreturns 0. ... On Error GoTo OpenError ...
    (microsoft.public.vb.general.discussion)
  • My, my, lookie here...
    ... Newsgroups: it.test,alt.usenet.kooks ... Subject: VOTE! ... nigger to sit around all day doing nothing for its ... Angela's walnut opens near our egg after we mould outside it. ...
    (rec.arts.marching.drumcorps)
  • Re: Messages of "Make sure you typed the name correctly"
    ... I am compelled to provide some feedback ... Double-click on same item again - it opens with no problem. ... You should consider setting up a newsreader to access these ... http://aumha.org/nntp.htm - list of MS newsgroups ...
    (microsoft.public.windows.vista.general)
  • Re: Messages of "Make sure you typed the name correctly"
    ... Double-click on same item again - it opens with no problem. ... You are using a web interface that just slurps Usenet ... You should consider setting up a newsreader to access these groups ... Here are some links to information about newsgroups: ...
    (microsoft.public.windows.vista.general)