*.exe problem ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: *.exe problem ?

  1. #1
    Join Date
    Mar 2004
    Posts
    70

    *.exe problem ?

    I have completed my project and make a *.exe for the VB program.

    There is no problems with the functions of *.exe.

    The pronblem is that when i have exited the *.exe, inside the task manger , the *.exe is still running.

    It is any good idea to terminate the *.exe completely.......




    Sami.

  2. #2
    Join Date
    Aug 2003
    Location
    London
    Posts
    515
    You may have forms still loaded....

    Write an exit point for the application in a standard module...in this exit routine, destroy all global variables and every form in the forms collection...

    eg;

    Code:
    Public Sub UnloadApplication
    
        Dim frm As Form
    
        Set g_myObject = Nothing
    
        For Each frm in Forms 
            Unload frm
            Set frm = Nothing
        Next
    
    End Sub
    Just call this routine when you application is going to close...

  3. #3
    Join Date
    Oct 2002
    Location
    Serbia & Montenegro
    Posts
    64

    End statement...

    Hi sami1983,

    This Sub can be replaced by simple End statement
    For example:

    Code:
    Public Sub UnloadApplication()
         End
    End Sub
    End statement unloads all active(loaded) forms.

    Regards,
    Jovan
    Last edited by Jovan; April 15th, 2004 at 07:25 AM.

  4. #4
    Join Date
    Apr 2004
    Posts
    18
    You shouldn't use the End statement to terminate a program. There is somthing in your program that is keeping it from unloading properly. I've seen this happen with sub-forms, database connections and Crystal Reports. Using the End statement can lead to corrupt data in your database (if you're using one) and other maladies caused by the improper termination of an object without releasing its dependencies (memory leak.) The proper solution is to unload *everything* in the Form_QueryUnload event procedure. Then the application will end on the when the Unload event has completed. If you're using the .Hide method on a sub-form then that is likely the culprit.

  5. #5
    Join Date
    Mar 2004
    Posts
    70
    Thanks a lot all guys here.

    The problem has been solved.It was due to some some hiden forms that i had not closed yet.





    Sami.

  6. #6
    Join Date
    Mar 2004
    Posts
    70
    Hi, Dmorley. The Sub given by u works perfect, but one thing that:
    Sometimes, the user exit the form just by closing it rather than go through by pressing "Exit" button.
    If they do in such way, the Sub will not be called and the *.exe is still running.

    Hope that u can get what i mean.....

    Thanks..









    Sami

  7. #7
    Join Date
    Aug 2003
    Location
    London
    Posts
    515
    Sami,

    Don't call the UnloadApplication routine directly from the cmdExit_Click event, instead call it from the Form_Unload or Form_QueryUnload events.

    In cmdExit_Click, you can just write something like...

    Unload Me

    And then...

    Private Sub Form_Unload

    Call UnloadApplication

    End Sub

    This way, if your user clicks on Exit or if they close the window using the X button, the UnloadApplication routine is always called...

    Hope that helps...

  8. #8
    Join Date
    Mar 2004
    Posts
    70
    That's what i need......

    Thanks for ur kindly help, Dmorley.




  9. #9
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    a note: avoid calling it motre than once...

    In main form:
    Code:
    Private sub Query_Unload(....)
    
        Dim frm As Form
    
        Set g_myObject = Nothing
    
        For Each frm in Forms 
            'avoid calling this code from here! 
            If frm.Hwnd<>me.Hwnd then
               Unload frm
               'Set frm = Nothing 'do not need this, but you could keep it
            End If
        Next
    
    
    end sub
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center