473,327 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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 20799
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: salo | last post by:
hi at visual basic 6 i write this to the button1_cl1ck unload form1 form2.show
4
by: V.Boomessh | last post by:
Hai can any one help me on this problem. I am new to VB.NET. I have 2 forms. (form1 and form2) On click of a button in form1 i want to show form2 and unload form1
4
by: Claudia Fong | last post by:
Hi, I have more than one forms in my program, and I would like to for example, in form1, I will call form2 and in form2 it will call form3. But the problem is when I call form2.Show, it does...
2
by: brianbender | last post by:
I am trying to load and unload assemblies dynamically and call methods and properties when loaded into an Appdomain I can load assemblies all day in the current AppDomain without references and...
3
by: Gauthier Segay | last post by:
Hello, I've an application where all my pages implement a PAGE_CODE string property, this property is stored in HttpContext.Current.Items. In some page, I must persist data in session while...
8
by: Sender | last post by:
In VB6.0 we use Unload Form1 to unload (close) form1 - what shall we have to write to unload a form in VB.Net
2
by: sam | last post by:
I want to know how to unload form / application in VB.Net. In VB 6, the coding is Unload Me but how about VB.Net? VB.Net 1.1 Coding -------------------- Private Sub InitializeComponent()...
1
by: Donkey Cart Racer | last post by:
Hi, I have a page - page1 which opens a window1 where users can look at tasks, in window1 users can click and open window2 where they can create new tasks I want to refresh window1 when...
5
by: =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post by:
It seems that one page XBAP whose Unloaded event never get called, I need put some clearing stuff (I.G stop dispatcher time) when user close browser, it unload event doesn't work, where shall I...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.