Results 1 to 10 of 10

Thread: [RESOLVED] Force END

  1. #1

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Resolved [RESOLVED] Force END

    when i close my program it keeps running in the background as a process what can i put under the form unload even to close eveything that the program does
    Last edited by WilliamRobinson; Jul 19th, 2005 at 06:02 AM.
    Nothing is Impossible you say?......Try slamming a revolving door!

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Force END

    On Error Resume Next
    '/////////////////////////////
    'clear out all open forms
    '/////////////////////////////
    Dim MyForm As Form
    For Each MyForm In Forms
    Unload MyForm
    Set MyForm = Nothing
    Next MyForm
    End

  3. #3
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Force END

    Put END as the last statement in your form_unload to kill everything. But better than this is to spend some time and find out why your program is not terminating. May be some infinite loop or someting may be the cause.

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  4. #4

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Re: Force END

    Thanks a mill

    worked fine
    Nothing is Impossible you say?......Try slamming a revolving door!

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Force END

    That will not close ALL objects. You have to do something like the code that was posted. Here is what I use, and it hasn't failed me, yet.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  Dim frm As Form
    5.   Dim obj As Object
    6.   For Each frm In Forms
    7.      If frm.Name <> Me.Name Then ' Unload this form LAST
    8.        For Each obj In frm
    9.          On Error Resume Next
    10.            Unload obj
    11.            Set obj = Nothing
    12.        Next
    13.        Unload frm
    14.        Set frm = Nothing
    15.      End If
    16.     Next
    17.     On Error Resume Next
    18.       For Each obj In frm
    19.         Unload obj
    20.         Set obj = Nothing
    21.       Next
    22.       Set frm = Nothing
    23.       Unload Me
    24. End Sub

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Force END

    Quote Originally Posted by dglienna
    That will not close ALL objects. You have to do something like the code that was posted. Here is what I use, and it hasn't failed me, yet.
    It will fail here and this is exactly the situation I was talking about in my post #3 (infinite loops)
    VB Code:
    1. Private Sub Form_Load()
    2.     Me.Show
    3.     Do
    4.         DoEvents
    5.     Loop
    6. End Sub

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Force END

    Quote Originally Posted by dglienna
    That will not close ALL objects. You have to do something like the code that was posted. Here is what I use, and it hasn't failed me, yet.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.  Dim frm As Form
    5.   Dim obj As Object
    6.   For Each frm In Forms
    7.      If frm.Name <> Me.Name Then ' Unload this form LAST
    8.        For Each obj In frm
    9.          On Error Resume Next
    10.            Unload obj
    11.            Set obj = Nothing
    12.        Next
    13.        Unload frm
    14.        Set frm = Nothing
    15.      End If
    16.     Next
    17.     On Error Resume Next
    18.       For Each obj In frm
    19.         Unload obj
    20.         Set obj = Nothing
    21.       Next
    22.       Set frm = Nothing
    23.       Unload Me
    24. End Sub
    Don't you only need to call On Error Resume Next once, like as the first line of this sub?

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Force END

    Never had a problem with it, and it only gets called once. I really don't think the first object would be an error. Only when an object doesn't exist.

    Not sure, but I think it's for the FOR EACH object IN Forms only.

  9. #9
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Force END

    On Error Resume Next resumes to the next line of code after the sub, which means it's pretty much an Exit Sub/Function only when an error has occured. Which is why it only needs to be called once. I rewritten your code to use modularly:

    VB Code:
    1. Public Sub Close_Program(Main_Window As Form)
    2.  
    3.     On Error Resume Next
    4.  
    5.     Dim Frm As Form
    6.     Dim Obj As Object
    7.    
    8.     For Each Frm In Forms
    9.        
    10.         If Frm.Name <> Main_Window.Name Then  ' Unload this form LAST
    11.        
    12.             For Each Obj In Frm
    13.                
    14.                 Unload Obj
    15.                
    16.                 Set Obj = Nothing
    17.            
    18.             Next Obj
    19.            
    20.             Unload Frm
    21.        
    22.             Set Frm = Nothing
    23.            
    24.         End If
    25.        
    26.     Next Frm
    27.    
    28.     For Each Obj In Frm
    29.        
    30.         Unload Obj
    31.        
    32.         Set Obj = Nothing
    33.      
    34.     Next Obj
    35.      
    36.     Set Frm = Nothing
    37.    
    38.     Unload Main_Window
    39.    
    40.     End
    41.    
    42. End Sub

  10. #10

    Thread Starter
    Addicted Member WilliamRobinson's Avatar
    Join Date
    Feb 2005
    Posts
    219

    Re: Force END

    Ok thanks every1 for your time this is now resolved
    Nothing is Impossible you say?......Try slamming a revolving door!

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