October 22, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Unloading All Forms in Visual Basic

  • November 18, 2002
  • By John Percival
  • Send Email »
  • More Articles »

How do you close your Visual Basic program? Do you use the End method? In this tip I will explain why using the End method is not the best way to close your program. It is an undocumented fact that using the End method does not completely remove all forms from memory. This means that your program does not give up all resources to other processes when it is closed using the end method. The only way to completely shut down the program is to unload each of the forms using the Unload method. Here is some code that loops through all loaded forms and unloads them one by one. As soon as no forms are loaded, your program has been closed.

Public Sub UnloadAllForms()
Dim Form As Form
   For Each Form In Forms
      Unload Form
      Set Form = Nothing
   Next Form
End Sub

It is best to call this procedure from the unload event of your main form.






Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel