When a user has finished with a dialog, they will want to close it by clicking a OK button of some sorts. To hide a dialog, you can use the Hide method. The following code hides Dialog1.
Dialog1.Hide
Using the Hide method does what is says. It hides the dialog. The dialog is not actually removed from the memory. When you use the Show method again, any controls will have kept their values. This is useful if the dialog will be shown and hidden a lot. However, forms such as the Splash form that will only be shown once should be removed from the memory. To do this, use the Unload method. If you do not do this, you will end up with lots of forms in the memory, not being used. If you have many forms with lots of controls saved in the memory, you may find you application eats up all the avaiable memory, and the whole system crashed. If you need to keep some values, save them to a variable, which can be accessed again when you need to load the form again. The following code removes Dialog1 from the memory.
Unload Dialog1
A very common mistake is to use the End statement. This is not good practice, as it does not always free up any of the memory that was allocated for your application.
When you Unload a form, its QueryUnload and Unload events occur. In both events, you can cancel the form unloading by setting Cancel = -1. In the QueryUnload event, you can also find out how the form is being unloaded by checking the UnloadMode value. This can be one of the following:
Constant | Description |
vbAppTaskManager (3) | Windows Task Manager is closing the application. |
vbAppWindows (2) | Current Windows session ending. |
vbFormCode (1) | Unload method invoked from code. |
vbFormControlMenu (0) | User has chosen Close command from Control menu box on form, or clicked the X button. |
vbFormMDIForm (4) | MDI child form is closing because the MDI form is closing. |
vbFormOwner (5) | The owner of the form is closing. |
Comments