469,315 Members | 1,802 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,315 developers. It's quick & easy.

How to unload after a Close?

I have written a Visual Basic program that does a long calculation and
writes the results to disk as it runs. If I click the Close button the
window closes but the program keeps running. How can I get the program
to recognize that its window has been closed and quit running?

-Harry http://home.netcom.com/~hjsmith

Jul 17 '05 #1
5 20550
> If I click the Close button the
window closes but the program keeps running. How can I get the program
to recognize that its window has been closed and quit running?

-Harry http://home.netcom.com/~hjsmith


Harry,
I don't consider myself a VB expert but I think your problem is
rather simple. When you click your "Close" button, you're only
closing the Form but not unloading it from memory.
There exists an "Unload" event for a Form. In your Sub
Close_Click() event, you need to call the Unload event. This will
unload your Form from memory.

Private Sub cmdClose_Click()
Unload Me 'or use the name of your Form in place of
Me
End Sub

Or, if you want to completely quit the program by clicking your Close
button try this(after Saving all necessary data, of course):

Private Sub cmdClose_Click()
End
End Sub

Hope this helps.

Peace,

Kris
Jul 17 '05 #2
"Kris" <kp*****@yahoo.com> wrote in message
news:6b*************************@posting.google.co m
If I click the Close button the
window closes but the program keeps running. How can I get the
program to recognize that its window has been closed and quit
running?

-Harry http://home.netcom.com/~hjsmith
Harry,
I don't consider myself a VB expert but I think your problem is
rather simple. When you click your "Close" button, you're only
closing the Form but not unloading it from memory.
There exists an "Unload" event for a Form. In your Sub
Close_Click() event, you need to call the Unload event. This will
unload your Form from memory.

Private Sub cmdClose_Click()
Unload Me 'or use the name of your Form in place of
Me
End Sub


Unload Me is best since it is more generic; if you ever create multiple
instances of the form you don't have to recode
Or, if you want to completely quit the program by clicking your Close
button try this(after Saving all necessary data, of course):

Private Sub cmdClose_Click()
End
End Sub


END is never needed in a VB app and can cause harm if used improperly; the
general rule of thumb is NEVER use it. VB apps terminate when no code is
running and all forms are unloaded.

Jul 17 '05 #3
>"Bob Butler" <ti*******@nospam.com> wrote in message news:<u1v7b.14755>

END is never needed in a VB app and can cause harm if used improperly; the
general rule of thumb is NEVER use it. VB apps terminate when no code is
running and all forms are unloaded.


Thanks for your input, Bob. I'm always learning new things. Since I
wasn't aware of this about the "End" statement, in your opinion, what
is the best way to quit a desktop application upon clicking an Exit
(command) button?

Thanks,

~kris
Jul 17 '05 #4
kp*****@yahoo.com (Kris) wrote in message
Since I wasn't aware of this about the "End" statement, in your opinion,
what is the best way to quit a desktop application upon clicking an Exit
(command) button?


Don't bother replying to this thread. I found a really nice summary
of the "End" statement in an archive on this list.

See: Subject: Notes on VB 'End' Statement [was Re: X to exit ]
From: Rob Strover (di********************@yahoo.com)
Date: 2002-11-14 08:32:10 PST

~kris
Jul 17 '05 #5
Thanks for your help.

I did not see how to add cmdClose_Click to my code.

I read an earlier post and figured it out from there. I already had a
quit flag so the new code was:

Private Sub Form_QueryUnload(cancel As Integer, unloadmode As Integer)
mbQuit = True
End Sub

In the main loop of the program I added:

If mbQuit Then Unload Me: oFormOwner.Show: Exit Sub

This worked great for me.

-Harry
"Bob Butler" <ti*******@nospam.com> wrote in message
news:u1v7b.14755$QT5.5892@fed1read02...
"Kris" <kp*****@yahoo.com> wrote in message
news:6b*************************@posting.google.co m
If I click the Close button the
window closes but the program keeps running. How can I get the
program to recognize that its window has been closed and quit
running?

-Harry http://home.netcom.com/~hjsmith
Harry,
I don't consider myself a VB expert but I think your problem is
rather simple. When you click your "Close" button, you're only
closing the Form but not unloading it from memory.
There exists an "Unload" event for a Form. In your Sub
Close_Click() event, you need to call the Unload event. This will
unload your Form from memory.

Private Sub cmdClose_Click()
Unload Me 'or use the name of your Form in place of Me
End Sub


Unload Me is best since it is more generic; if you ever create

multiple instances of the form you don't have to recode
Or, if you want to completely quit the program by clicking your Close button try this(after Saving all necessary data, of course):

Private Sub cmdClose_Click()
End
End Sub
END is never needed in a VB app and can cause harm if used improperly;

the general rule of thumb is NEVER use it. VB apps terminate when no code is running and all forms are unloaded.

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by salo | last post: by
4 posts views Thread by V.Boomessh | last post: by
4 posts views Thread by Claudia Fong | last post: by
2 posts views Thread by brianbender | last post: by
3 posts views Thread by Gauthier Segay | last post: by
2 posts views Thread by sam | last post: by
1 post views Thread by Donkey Cart Racer | last post: by
5 posts views Thread by =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.