Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 135,982 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,230 people online right now. Registration is fast and FREE... Join Now!




Closing the program

 
Reply to this topicStart new topic

Closing the program

centers
25 Sep, 2007 - 12:14 PM
Post #1

New D.I.C Head
*

Joined: 25 Sep, 2007
Posts: 2


My Contributions
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 Sep, 2007 - 01:19 PM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Closing The Program
25 Sep, 2007 - 03:55 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,179



Thanked: 208 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
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...

CODE

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.

smile.gif
User is online!Profile CardPM
+Quote Post

born2c0de
RE: Closing The Program
26 Sep, 2007 - 06:22 AM
Post #3

printf("I'm a %XR",195936478);
Group Icon

Joined: 26 Nov, 2004
Posts: 3,906



Thanked: 34 times
Dream Kudos: 2800
Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions
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
User is offlineProfile CardPM
+Quote Post

centers
RE: Closing The Program
26 Sep, 2007 - 06:39 PM
Post #4

New D.I.C Head
*

Joined: 25 Sep, 2007
Posts: 2


My Contributions
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?


QUOTE(Martyr2 @ 25 Sep, 2007 - 04: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...

CODE

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.

smile.gif


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 10:47AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month