472,374 Members | 1,283 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 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 20695
> 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...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

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.