Difference between revisions of "End"

From HashVB
Jump to: navigation, search
(Moved from http://www.earlsoft.co.uk/tips/end.php)
 
m (Disambiguated the sample)
 
Line 20: Line 20:
 
If you are going to have lots of forms open and you just want to shut them down, you can use a version of the code above:
 
If you are going to have lots of forms open and you just want to shut them down, you can use a version of the code above:
  
  Dim Form As Form
+
  Dim LeftoverForm As Form
  For Each Form In Forms
+
  For Each LeftoverForm In Forms
   Unload Form
+
   Unload LeftoverForm
 
  Next
 
  Next
  
 
Happy endings all round...
 
Happy endings all round...

Latest revision as of 09:40, 11 July 2007

So, your application isn't shutting down properly? You may think there is an easy way around this:

End

No! End is the equivalant of stopping your car by driving it into a brick wall (stolen from a DevX newsgroup years ago :o). It does NO clean up at all, it stops the process dead. This is especially bad if you are doing any form of database or hardware access.

"What is likely to cause my application to stay running?"

An application will shut down cleanly when and only when:

  1. All forms are unloaded.
  2. All code has stopped running.

The first item is the most common cause, and there is a relatively easy way to find the culprit. Try running the following code in the Immediate/Debug window:

For Each Form In Forms: Print Form.Name: Next

This will print the name of all the currently loaded forms. If these forms shouldn't be loaded, then you need to track down where is loading them. Any code that references the user interface of a form will cause it to be loaded and left.

If you are going to have lots of forms open and you just want to shut them down, you can use a version of the code above:

Dim LeftoverForm As Form
For Each LeftoverForm In Forms
  Unload LeftoverForm
Next

Happy endings all round...