Closing program trouble.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 22

Thread: Closing program trouble.

Hybrid View

  1. #1
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20

    Closing program trouble.

    HY!

    My program works with access files *.mdb. Everything is working, but when i push the close button the program close itself, but it remains in memory (i can see this when i press Ctr+Alt+Del). My program is working on WinXP. The close button's code is Unload Me. What can be the problem?

  2. #2
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,209

    send some code please

    are you sure that ALL forms were unloaded not just hidden ?
    I a form is still loaded the App. won't close.

  3. #3
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20

    Yep, i've checked

    I've double checked. All the forms have only one exit button and they all have tis kind of code:

    Private Sub exit_Click()
    Unload Me
    End Sub

    Even if i start the aplication and click the exit button it still remains hidden in process bar.

  4. #4
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,209
    Does the form it use an activeX control that does not anload ? (happens if a bug in the control causes it not to terminate).

    Do you access the database over a slow network so it takes time to close the connection ?

  5. #5
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20

    no activex or slow network

    I'm not using any activex neither access over a network. The database files are access files (mdb). I think that the problem comes from there somewhere, a connection to that database is not closed, but the forms that work with the database are created automatic by the VB6 wizzard.

  6. #6
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097
    Do forms reference each other? You could have a chain of circular references.....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  7. #7
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20
    I have a main form within i call several other forms. I'm using variabiles from one form in another form. I don't know if that can generate circular references.

  8. #8
    Join Date
    Apr 2004
    Location
    Austria
    Posts
    43
    Unload me isn't closing the whole app..

    Add to your Exit Button the Code:

    Exit() (or something like that) and your program will close without you having to think about any forms that may be still open

    greetings UNI

  9. #9
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726
    In query_unload of your main form add this code:

    Code:
    'Private sub Query_Unload(....) 
    dim frmX as form
    For each frmX in Forms
    
       If frmX.Hwnd<> Me.Hwnd then
             Unload frmX
       end if
    
    Next
    dim sMessage as string 
    If Forms.Count>1 then
       For each frmX in Forms
    
            If frmX.Hwnd<> Me.Hwnd then
                 sMessage =sMessage & frmX.Name & " "
            end if
    
        Next
         Msgbox "Something made " & sMessage & " not closing correctly"
    end if
    '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.

  10. #10
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,209
    Originally posted by Illuvatan
    Unload me isn't closing the whole app..

    Add to your Exit Button the Code:

    Exit() (or something like that) and your program will close without you having to think about any forms that may be still open

    greetings UNI
    you mean END ?
    it's not preferable to call END

    from msdn :
    Note The End statement stops code execution abruptly, without invoking the Unload, QueryUnload, or Terminate event, or any other Visual Basic code. Code you have placed in the Unload, QueryUnload, and Terminate events of forms and class modules is not executed. Objects created from class modules are destroyed, files opened using the Open statement are closed, and memory used by your program is freed. Object references held by other programs are invalidated.

  11. #11
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20

    Smile Success

    For the last 3 posts:

    1) The Exit commands didn't help. I think that this command only interrupts a for, if, or sub execution without doing anythig else.

    2) I'm not quite sure where to put that code. I've put it in the exit sub of the main form. Did i do good?
    Putting the code in the exit sub didn't display any messages but also stopped from closing my application. I guess smthin' wrong.

    3) An the last but not least and also THE SOLUTION were these three "magic" letters: END . I've commented the Unload Me and the code from Cimperiali and writted the END statement. My exit sub looks like this now:

    Private Sub Iesire_Click()
    End
    End Sub

    So i think that the problem is solved and i thank to all who helped me.

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

    End - abrubpty terminate program

    as hspc stated, End is to avoid: it terminates abruptly your code.
    Obejcts that need to enter the Terminate_event (or even the
    Unload_ procedure) to make cleanup, will not enter that code,
    thus nothing is correctly cleaned....Better should be to step inside
    code and try to understand what is going wrong (there is always
    a "why" if a program does not really stop...). You may think you
    have solved, now, and maybe it will work for you. But maybe a
    bug will come out soon....
    ...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.

  13. #13
    Join Date
    Aug 2003
    Location
    London
    Posts
    515
    Yes - don't use 'End', especially when working with Access databases.....you could corrupt your database quite easily...

    Unloading each of the forms in the forms collection is the correct approach, use the code that Cimperiali has provided - it will work if in the right place & called correctly!

  14. #14
    Join Date
    Mar 2003
    Location
    Romania
    Posts
    20

    second thoughts

    I guess there is a good reason why my program won't end well when i call the Unload command, but i can't figure it out why...all my forms have the unload command yet the program isn't ending.
    Cimperiali gave me a code but i don't know where to put it. Could u give me a little more details, a little project where the code is implementing and working pls?

  15. #15
    Join Date
    Mar 2004
    Posts
    30

    Re: send some code please

    Originally posted by hspc
    are you sure that ALL forms were unloaded not just hidden ?
    I a form is still loaded the App. won't close.
    what is the 'me' part for in vb? i've seen this alot but i don't have a clue what it's about.

Page 1 of 2 12 LastLast

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center