|
|
Title | Unload an application's forms in reverse order of creation |
Description | This example shows how to unload an application's forms in reverse order of creation, stopping if any don't unload, in Visual Basic 6. |
Keywords | close, unload, form |
Categories | Software 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:
|
|
|
|
|
|