Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

The Unload Statement

The Exit command button's Click event procedure contains a statement you haven't seen until now. The Unload statement unloads a form from memory. If the form to unload is currently displayed, Visual Basic removes the form and returns all the form's control values back to their design-time state.

In most cases the Unload statement is unnecessary, especially when your application contains only a single form. If you add multiple forms to the application, however, the user could have closed one of the Form windows (by clicking the form's window close buttons), and the End statement could fail to release that form's resources properly.

The Unload statement lets you use a shortcut that looks like this:

Unload Me

Me is a special object that refers to the currently active form. Use Unload Me when the application contains only a single form if you don't want to type the full form name. For a multiple-form application, however, be sure to unload all the forms before terminating the program.

Share ThisShare This

Informit Network