dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: closing properly

  1. #1
    Join Date
    Jan 2010
    Posts
    5

    closing properly

    I have a simple VB6 application with 1 form and I open several recordsets through an ADODB connection to an Access database and fill in several datagrids. So far, I am not allowing updates to the database (view only), but I may add some updating abilities.

    I am wondering what the proper way to close this type of application is. I am currently just doing an Unload Form in the Exit button. Is that all I need to do?

    Rick

  2. #2
    Join Date
    Jun 2009
    Posts
    135
    The proper way would be to close any remaining recordset objects, command objects, and connections in the unload event. Also, in this event you would destroy, remove, close anything else you instantiated.



    Good Luck

  3. #3
    Join Date
    Jan 2010
    Posts
    33
    VB6 / 5 whatever, can be a bugger of a thing for when it comes to terminating. Even some of the best programmers scream out "memory leaks, memory leaks" many moons after they believed that their project was done and dusted. This is particularly so the case when YOU'RE using an infinite loop in your program.

    My best advice is the following:
    Code:
    Private Sub Form_Unload(Cancel As Integer)
    '------------------------------------------------------------------------------------------------------------------
    ' Purpose: Terminate application
    '------------------------------------------------------------------------------------------------------------------
       
       Set frmGUI = Nothing
       
       Dim i As Long
       
       For i = Forms.Count - 1 To 0 Step -1
          Unload Forms(i)
       Next
    
       End
    End Sub
    Set your dB to nothing and all other class instances as well. If YOU'RE using APIs, delete all DCs (device contexts) , after which throw in an END. Nothing wrong with END if you have cleaned up properly. If you haven't, Windows will do it for you eventually. Easy greasy.

  4. #4
    Join Date
    Jun 2009
    Posts
    135
    Using the End statement is the fastest way in which to create memory leaks, even if you think you have cleaned everything up!!!

  5. #5
    Join Date
    Jan 2010
    Posts
    33

    Post

    Yeah it is debatable.

    There is good argument on both sides.

    Try getting out of a complex infinite loop without it though. Fairly quirky.

  6. #6
    Join Date
    Jan 2010
    Posts
    5
    Thanks for the suggestions.

    I have also seen some code that sets the connection and the recordset = nothing.
    Is that necessary?

  7. #7
    Join Date
    Jun 2009
    Posts
    135
    Yes, if you create an object, control, reference, or whatever, you should dispose of all of these things. Other languages, make you dispose of these things but the vb runtime can take care of some of the management of these things for you but ask yourself this. Do you think of everything? Do you think the designers of VB thought of everything? So yeah! It's best if you do all this yourself.



    Good Luck

  8. #8
    Join Date
    Jan 2010
    Posts
    33

    Post

    Quote Originally Posted by vb5prgrmr View Post
    Yes, if you create an object, control, reference, or whatever, you should dispose of all of these things. Other languages, make you dispose of these things but the vb runtime can take care of some of the management of these things for you but ask yourself this. Do you think of everything? Do you think the designers of VB thought of everything? So yeah! It's best if you do all this yourself.
    You sound just like Mister_e

  9. #9
    Join Date
    Jan 2010
    Posts
    33

    Post

    Incidentally, why don't you try and get Spatial Matrix to unload properly without using an END

    What a pain in the rear.

Similar Threads

  1. Completely closing out a form ...
    By Shannon in forum VB Classic
    Replies: 5
    Last Post: 08-31-2009, 07:53 AM
  2. JPanel print message after closing it
    By aleplgr in forum Java
    Replies: 0
    Last Post: 08-30-2007, 01:11 PM
  3. Unable to Unload and/or End Program Properly
    By JSThePatriot in forum VB Classic
    Replies: 8
    Last Post: 04-22-2007, 12:19 AM
  4. Workbook not Closing Properly by Excel VBA
    By blayne in forum VB Classic
    Replies: 1
    Last Post: 11-17-2005, 07:14 PM
  5. Replies: 5
    Last Post: 04-26-2002, 07:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center