Results 1 to 5 of 5

Thread: How to end a VB program?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 1999
    Location
    Linköping, Sweden
    Posts
    19

    Arrow

    Sometimes when I end a VB program a process remain running in the background. How can I close a VB program and be sure that no threads or processes remain running? Is there any code I should have in the unload event or something?
    /Magnus

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    A VB program ends after all of its forms have been unloaded, or when the "End" statement is executed.

    "End" is a harsh way to end the application is generally not recommended.

    Could it be that you hid, but did not unload a form? If so, the program may appear to have ended, but a form is still in memory.

    Also, when you unload a form, setting it to Nothing will clear out any form-level variables that were declared in that form. In the Form_Unload event, I usually code:

    Set Form1 = Nothing
    "It's cold gin time again ..."

    Check out my website here.

  3. #3
    Guest
    As a rule, I try to let VB execute as many of the program's events (when closing) as possible, this ensures that 'dirty' files are saved when necessary.

    As Brucey says, just stopping the program isn't a good idea.

  4. #4
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Try this code:
    Code:
    For Each Form In Forms
        Unload Form
    Next

  5. #5
    Guest
    Code:
    Sub DestroyAll()
    
        Dim frm As Form
        For Each frm In Forms
            Unload frm
            Set frm = Nothing
        Next frm
    
    End Sub
    Usage
    Code:
    Private Sub Command1_Click
        DestroyAll
    End Sub

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