BUG: Error When Closing a Program Through the Control Box

Last reviewed: October 14, 1996
Article ID: Q143046
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic for Windows, 32-bit only, version 4.0

SYMPTOMS

An application error occurs when you close a Visual Basic program through the control box if the Visual Basic program executes a command after an object created from a class module is set to nothing. This problem occurs only in the 32-bit edition of Visual Basic 4.0.

WORKAROUND

The workaround to this issue is execute all the code in the event before setting the object to nothing. The statement to set the object to nothing should be the last line in the event procedure.

STATUS

Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. Microsoft is researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

Steps to Reproduce Issue

  1. Start the 32-bit version of Visual Basic 4.0 or if it is already running, click New Project on the File menu.

  2. Use the following steps to create a class module.

        - Click Class Module on the Insert Menu. The code window for the class
          module appears.
    

        - In the Properties window of the Class1 class module, set the
          Instancing Property to 2-Createable MultiUse, and the Public property
          to True.
    

        - Add the following code to the Class1 code window:
    

          Option Explicit
          Public Name As String
          Private Sub Class_Terminate()
    
             Form1.Print Name
          End Sub
    
    

  3. Add the following code to the Form1 code window.

          Option Explicit
          Public A As New Class1
    

          Private Sub Form_Load()
    
             Show
             Set A = New Class1
             A.Name = "A"
    
             'To workaround this bug, cut the next line
             Set A = Nothing
    
             Print "A Is " & IIf(A Is Nothing, "Nothing", "Something")
             'And uncomment this next line.
             'Set A = Nothing
          End Sub
    
    

  4. Press the F5 key or click Start on the Run menu to run the program.

  5. Click Close from the Control Bar menu on the form. One of the following application error displays and Visual Basic ends:

    Windows NT 32-bit:

          An application error has occurred and an application
          error log is being generated, VB32.exe Exception: access
          violation (0xc0000005), Address: 0x001d02d7.
    

          -or-
    

          VB32.EXE-Application Error dialog box. The instruction
          at "0x001aaff8" referenced memory at "0x007dbd6b". The
          memory could not be "written".
    

    Windows 95 32-bit:

         VB32 caused an invalid page fault in module <unknown> at
         0000:a0000001.
    


Additional reference words: 4.00 vb4win vb432
KBCategory: kbprg kbbuglist
KBSubcategory: IAPOLE PrgCtrls


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 14, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.