Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUnload an application's forms in reverse order of creation
DescriptionThis example shows how to unload an application's forms in reverse order of creation, stopping if any don't unload, in Visual Basic 6.
Keywordsclose, unload, form
CategoriesSoftware Engineering, Controls
 
This program's forms have a combo box labeled "Don't Close." The QueryUnload event handler checks its value and refuses to let the form unload if the combo box is checked.
 
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode _
    As Integer)
    Cancel = (cboDontClose.Value = vbChecked)
End Sub
 
Click the New button to make a new instance of the program's form. Click the Close All button to run the following code, which loops through the Forms collection unloading the forms, most recently created first. After it tries to unload a form, the code checks to see if the number of forms in the Forms collection matches the variable i. If Forms.Count <> i, then the form refused to unload and the program exits its loop.
 
Private Sub cmdCloseAll_Click()
Dim i As Integer

    For i = Forms.Count - 1 To 0 Step -1
        Unload Forms(Forms.Count - 1)
        If Forms.Count <> i Then Exit For
    Next i
End Sub
 
See also:

 
 
Copyright © 1997-2006 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated