Results 1 to 8 of 8

Thread: best way to TOTALY kill an App???

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2002
    Location
    England, Bedfordshire
    Posts
    112

    best way to TOTALY kill an App???

    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 ??
    So Many things to do.....
    So little enthusiasm to do them.

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    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

  3. #3
    Addicted Member vigge89's Avatar
    Join Date
    May 2002
    Location
    Sweden
    Posts
    172
    Here's what i use:
    VB Code:
    1. Dim frmForm as Form
    2.  
    3. 'Unload all forms
    4. For Each frmForm In Forms
    5.     Unload frmForm
    6.     Set frmForm = Nothing
    7. Next
    8.  
    9. 'Kill app
    10. End

    Unloads all forms and sets them to nothing, and finally ends the app.


  4. #4
    Frenzied Member agmorgan's Avatar
    Join Date
    Dec 2000
    Location
    Lurking
    Posts
    1,383
    You might want to add object unloading iside that loop as well
    Something like
    VB Code:
    1. For Each object in frmForm
    2.     Set obj = nothing
    3. Next

  5. #5
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    setting each object to nothing is unnecessary: setting their container is good enough

    this will get the job done well

    VB Code:
    1. Private Sub mnuExit_Click()
    2.     Unload Me
    3. End Sub
    4.  
    5. Private Sub cmdExit_Click()
    6.     Unload Me
    7. End Sub
    8.  
    9. Private Sub Form_Unload(Cancel As Integer)
    10.     Unload Form2
    11.     Set Form2 = Nothing
    12.     Set Form1 = Nothing
    13.     End
    14. End Sub

  6. #6
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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:
    VB Code:
    1. Private Sub cmdShow_Click()
    2.    ShowForm
    3. End Sub
    4.  
    5. Private Sub ShowForm()
    6.    Form2.Show
    7. End Sub
    This can lead to sticky situations where previous varibles were not cleared properly etc.

    What you should do is:
    VB Code:
    1. Private Sub cmdShow_Click()
    2.    ShowForm
    3. End Sub
    4.  
    5. Private Sub ShowForm()
    6. Dim frmNew As Form2
    7.    Set frmNew = New Form2
    8.    Load frmNew
    9.    frmNew.Show
    10.    Set frmNew = Nothing
    11. End Sub
    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.

    Wooka

  7. #7
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    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

  8. #8
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    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
    Sorry, disagree.
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width