473,583 Members | 3,114 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 20831
> 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.goog le.com
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*******@nosp am.com> wrote in message news:<u1v7b.147 55>

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.c om (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_QueryUnloa d(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*******@nosp am.com> wrote in message
news:u1v7b.1475 5$QT5.5892@fed1 read02...
"Kris" <kp*****@yahoo. com> wrote in message
news:6b******** *************** **@posting.goog le.com
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
4197
by: salo | last post by:
hi at visual basic 6 i write this to the button1_cl1ck unload form1 form2.show
4
1931
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
21524
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 show the form2, but how can I unload form1? If I put form1.close, it will close everything. :(
2
6864
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 without interfaces if need be. But try as I may they will ot unload. I have been working on this problem for weeks. I have seen other apps using...
3
3204
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 the user perform operation on this page (postback navigation based). I also need to clean up the session data when the user leave the page (by a...
8
17925
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
22612
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() Me.SuspendLayout 'MainForm
1
8559
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 window2 closes and refresh page1 when window 1 closes
5
5892
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 put? -- ======================= Steven Tang SYWWUYU)
0
7896
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7827
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8184
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7936
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8195
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5375
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2334
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1434
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.