-
PLEASE HELP ME
Can I please ask what everyone else does to handle program terminations?
I want my program to unload,kill, remove, and otherwise stop running any time someone hits the little X in the corner or some selects quit.
My project has 4 forms in it. sometimes only 3 are loaded.
When one gets loaded I keep it in memory so that the user can go back to it the way they left it.
How can I handle the removal of all forms and stop the exe from running when any X gets hit or the user selects quit?
thank you for your time and have a good day
-
I would be very thankful for any advice on the subject.
thank you for your time and have a good day
-
Re : Unloading
Badger,
Create a global module. In this module create a sub, and do the following
eg.
sub myUnload()
unload form1
unload form2
unload form3
unload form4
end sub
in the unload events of yuor forms, insert code to kill and objects etc. then call myUnload()
so in each of the forms unload events, do someting similar to
private sub form_Unload(cancel as integer)
set myobject = nothing
myunload
end sub
Iain.
-
thank you very much that helped me out a lot
-
This will always close all forms no matter what their names are:
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
'close all sub forms
For i = Forms.Count - 1 To 1 Step -1
Unload Forms(i)
Next
End Sub
-
unloading without names
kedaman,
I have tried what you have suggested before, and the program went into a continous loop and stopped responding.
However i see your point that it does allow you to unload any form without having to know the name.
The folllowing method works without crashing.
Code:
Private Sub Form_Unload(Cancel As Integer)
Dim form As form
For Each form In Forms
Unload form
Next
End Sub
Iain.
-
That code i wrote works fine in my apps. But if one or more of your apps crash with it, I will copy your version. But I wonder if there really is anything that differs from yours.
-
Public Sub UnloadAllForms()
Dim Form As Form
For Each Form In Forms
Unload Form
Set Form = Nothing
Next Form
End Sub
crack
-
why dont you just do:
private sub form_unload(cancel as integer)
end
end sub
surely that would just terminate the whole thing easier, prolly not the best way but would certainly work!
-
it was my understanding that end would not free up all the resources.