What is the BEST way to Totally Kill an app Unload Me stil somtimes leaves an app running in the background
What the best way to kill EVERYTHING in an App compleatly ??
Printable View
What is the BEST way to Totally Kill an app Unload Me stil somtimes leaves an app running in the background
What the best way to kill EVERYTHING in an App compleatly ??
Obear
You need to unload anything that you have loaded into memory inside the program by setting all objects to nothing and unloading all loaded forms.
i.e Set object = Nothing
Here's what i use:
VB Code:
Dim frmForm as Form 'Unload all forms For Each frmForm In Forms Unload frmForm Set frmForm = Nothing Next 'Kill app End
Unloads all forms and sets them to nothing, and finally ends the app.
You might want to add object unloading iside that loop as well
Something likeVB Code:
For Each object in frmForm Set obj = nothing Next
setting each object to nothing is unnecessary: setting their container is good enough
this will get the job done well
VB Code:
Private Sub mnuExit_Click() Unload Me End Sub Private Sub cmdExit_Click() Unload Me End Sub Private Sub Form_Unload(Cancel As Integer) Unload Form2 Set Form2 = Nothing Set Form1 = Nothing End End Sub
2 things. Never use END.
It's sloppy, and if something isn't unloaded correctly, then the END command just ignores it, no Unload or Terminate events will fire.
I have just removed the END command from our works app, after pestering my boss for 12 months about it.
Guess what...once I did the app fell over all over the place because we, sorry, previous developers had not tidied up their code properly.
It's taken me 24hrs to fix this, but now things are terminated correctly.
There should NEVER be a need to use the END command.
It's almost as bad as NOT using Option Explicit :(
Also, never access the forms directly. IE:
Never do:
This can lead to sticky situations where previous varibles were not cleared properly etc.VB Code:
Private Sub cmdShow_Click() ShowForm End Sub Private Sub ShowForm() Form2.Show End Sub
What you should do is:
This gives you way more power in coding, plus it's a lot neater and you won't get tied up with forms not going out of scope properly.VB Code:
Private Sub cmdShow_Click() ShowForm End Sub Private Sub ShowForm() Dim frmNew As Form2 Set frmNew = New Form2 Load frmNew frmNew.Show Set frmNew = Nothing End Sub
Wooka
don't use end to acutally do the program close, but using it in Form_Unload add even more 'closure'
believe me if i thought it was just overkill i wouldn't use it, but i've seen it make a difference
Sorry, disagree.Quote:
Originally posted by dis1411
don't use end to acutally do the program close, but using it in Form_Unload add even more 'closure'
believe me if i thought it was just overkill i wouldn't use it, but i've seen it make a difference
There is NEVER any reason to use END.
Why do you use END? Have you got a valid reason to?
END is evil, and using it for more "closure" is a bad excuse and leads to sloppy coding, and/or, hides potential errors that have not been dealt with correctly :(
Woka