So what is the best way to Close or Exit a program?
This post has been edited by centers: 25 September 2007 - 01:19 PM
|
|
|
|
Closing the program
Page 1 of 1
Closing the program#1
Well I started writing code for a control simulator and before I knew it I had 40 Forms and 2 Modules. It runs well when I run it in the IDE but when I made it into an exe it ran ok but when I clicked on the close button (the X in the upper right hand corner) not all of the forms closed.
So what is the best way to Close or Exit a program? This post has been edited by centers: 25 September 2007 - 01:19 PM #2Posted 25 September 2007 - 03:55 PM
What you will want to do is loop through all the forms and unload them. VB will fully close as soon as you close all forms. This is even recommended over the use of End and can be done with a snippet like the following...
Public Sub UnloadAllForms() Dim objForm As Form ' Loop through all the forms and unload each For Each objForm In Forms Unload objForm Next Set objForm = Nothing End Sub Then all you have to do is call the function to unload all the forms loaded. I hope this is a solution that will work for you. Good luck. #3Posted 26 September 2007 - 06:22 AM Quote This is even recommended over the use of End Exactly. The End statement stops code execution abruptly without invoking the Unload, QueryUnload, or Terminate event, or any other Visual Basic code. Objects created from class modules are destroyed, files opened using the Open statement are closed, and memory used by your program is freed. Object references held by other programs are invalidated. The End statement provides a way to force your program to halt. For normal termination of a Visual Basic program, you should unload all forms. Your program closes as soon as there are no other programs holding references to objects created from your public class modules and no code executing. Source : MSDN #4Posted 26 September 2007 - 06:39 PM
Thanks for the snippet.
How would I trigger this? I'm thinking maybe put a cmdClose() in one of the modules. Would that be triggered from any of the forms if the Close ( X in the top right had corner of a form) was Clicked?
What you will want to do is loop through all the forms and unload them. VB will fully close as soon as you close all forms. This is even recommended over the use of End and can be done with a snippet like the following... Public Sub UnloadAllForms() Dim objForm As Form ' Loop through all the forms and unload each For Each objForm In Forms Unload objForm Next Set objForm = Nothing End Sub Then all you have to do is call the function to unload all the forms loaded. I hope this is a solution that will work for you. Good luck.
Page 1 of 1
Fast Reply
1 User(s) are reading this topic
|
||||||||
Forum Index:
Programming Help |
C and C++ |
VB6 |
Java |
VB.NET |
C# |
ASP.NET |
PHP |
ColdFusion |
Perl and Python |
Ruby |
Databases |
Other Languages |
Game Programming |
Mobile Development |
Software Development |
Computer Science |
Industry News |
52 Weeks Of Code |
Programming Tutorials |
C++ Tutorials |
Visual Basic Tutorials |
Java Tutorials |
VB.NET Tutorials |
C# Tutorials |
Linux Tutorials |
PHP Tutorials |
ColdFusion Tutorials |
Windows Tutorials |
HTML/JavaScript Tutorials |
CSS Tutorials |
Flash Tutorials |
Web Promotion Tutorials |
Graphic Design & Photoshop Tutorials |
Software Development Tutorials |
Database Tutorials |
Other Language Tutorials |
ASP.NET Tutorials |
Game Programming Tutorials |
WPF & Silverlight Tutorials |
Mobile Development Tutorials |
Python Tutorials |
Ruby Tutorials |
