Solved

Close (X) button does not close my application.

Posted on 2004-08-14
5
177 Views
Last Modified: 2010-05-02
My program terminate command is as follows:
  Form1.Hide
  Unload Form1
  End
This works well every time. However, when I use the windows standard (X) button in the upper right hand corner of the window, the application becomes invisible but remains running. The application appears in the task manager and can only be closed using "End Task". The average user will always use the (X) as a way to exit any application. How do I get the (X) button to terminate my program?
Thanks
0
Comment
Question by:StephenMShick
  • 3
5 Comments
 
LVL 14

Accepted Solution

by:
Farzad Akbarnejad earned 250 total points
Comment Utility
Hi,
Add End statement to QueryUnload events of forms that you want to click on their (X) button and terminate your program.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    End
End Sub

-FA
0
 
LVL 26

Expert Comment

by:Rejojohny
Comment Utility
The "End" is not a very good thing to be used as this stops the program abrubtly .. no cleaning of variables .. memory etc happens after the command .. use this code .. remove the ".Hide" .. it is not necessary for u to close the form ...

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   unload form1
   set form1 = nothing
End Sub
0
 
LVL 26

Expert Comment

by:Rejojohny
Comment Utility
ok cool .. u have anway accepted an answer .. but i will still say the "End" is not a nice solution ..understand y ur code was not working ... it was becuase the terminate event was not geting executed .. when u "unload form1" it does not really remove it from the memory .. using the set form1 = nothing would ensure that .. so ur code would still continue to work if u have this statement ..
0
 

Author Comment

by:StephenMShick
Comment Utility
Thanks to FarzadA and Rejojohny
I used a combination of both answers as shown below.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
   Unload Form1
   Set Form1 = Nothing
   End
End Sub

Unfortunately I ould only officially accept one answer. I selected the first because it did stop the program. The second answer did the clean up, but left it running. Still need the "End".
0
 
LVL 26

Expert Comment

by:Rejojohny
Comment Utility
the program was still running because some objects created within ur code is still "alive" probably becuase of the form1.hide method .. try removing it .. and without the "end" statement .. I am sure it will work ...

as i said .. the "END" statement has just ended everything at the spot .. that is not really a good solution .. basically u have not exited gracefully ...

have a look at these posting too
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21024448.html
(arthur's comment)

0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now