Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

processes still running when user exits prog with 'X'

Status
Not open for further replies.

ctlin

Technical User
Apr 17, 2002
77
US
i have some loops running that are infinite (waiting for input from another prog). if the user exits the program with the X in the upper right hand corner of the MDI during the loop, then the .exe still runs after all the form windows close (i know because i tried to recompile to the same name and access was denied - program must still be running right?). I don't think this happens if the user stops the program with the Exit option in my menu (which calls "End").

is there a way to disable the X in the upper right hand corner in an MDI form or at least link its clickage to something so that I can call "End" when it happens? thanks
 
Set the ControlBox property of the form to False - that should remove the X (and the min and max buttons)
Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein


 
Or another way to do it ctlin. Is to put your exit code from your exit button into the Form_Unload procedure.

For Unload is what is called whenever your program closes, so all you need to do is move your CommandExit code into this function and then in the exit button, put the Line

[tt]Unload me[/tt] Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
Technically, the X button is an Unload form button. There is no Close Program button. Even Unloading a form does not terminate the Form if there are still outstanding references to it, including module level variables that hold references to controls. Unloading is merely the process of releasing resources involved in displaying the form and its controls. The program will only exit after all forms terminate, not just unload. You can Force it with END but that is not recommended for VB.

Put a
Debug.print "form xxx terminated"
in the Form_Terminate event to see which forms actually terminate when unloaded. Do not make any reference to the form in this event like "Me.Name". Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
CajunCenturion- that option seems to be lacking for MDI windows

Craig- i put the following code in my MDI window:
------------
Private Sub Form_Unload()
End
End Sub
-------------

this still leaves the program running when i close the MDI window with the X so i don't think it is running this Sub when i click the X.
 
No what I was trying to say that might have been lost in translation of my technical mind.

Put the code that you had in the exit button into the unload event. So if your code once looked like.
[tt]
Private Sub cmdExit()
' Clean Up
' release all DLL's and links

m_Module1 = Nothing
m_Module2 = Nothing

' release all Recordsets and global variables
rs1 = nothing
str1 = nothing

' release anything else that may have a global
' link or relationship

' Close all forms

Unload Form2
Unload Form3
Unload Form1
End Sub
[/tt]
To make this work on the X so that it is the same as when you click your exit button is to change the code to look somthing like
[tt]
Private Sub cmdExit_Click()
Unload Form1
End Sub

Private Sub Form1_Unload()
' Clean Up
' release all DLL's and links

m_Module1 = Nothing
m_Module2 = Nothing

' release all Recordsets and global variables
rs1 = nothing
str1 = nothing

' release anything else that may have a global
' link or relationship

' Close all forms

Unload Form2
Unload Form3
End Sub
[/tt]
Now the code will exit the same way whether you click the exit button or if you click the X...

I hope that's a little more clear... Oh and as John said, never use END... I am a culprit I use end while debugging but only because I need relationships dropped between runs. But as soon as that product goes out the door, proper release code is replaced.
Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
I have a related question to this thread...

For simplicity, I have a programm with one command button. The following code is in the click event:

Private Sub Command1_Click()
Dim cnt as Double
for cnt = 0 to 5000000
DoEvents
next cnt
msgbox "all done counting"
End Sub

If the user clicks the 'X' on the form, then this loop will continue until it's done counting and then display the message box. So how would you stop the loop if the user presses the 'X' button.

Now I did find that if the cnt variable is declared in the declarations section, you can set the value so that the loop terminates (within the Form_Unload event). But what if, as above, the variable is local to the Sub routine?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top