CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2002
    Location
    United Kingdom
    Posts
    60

    My program is still running when I exit???

    Hi,

    I have a VB program (with a form called "Form1"), and when I exit and I press CTRL-ALT-DELETE to bring up the applications and processes it says that it is still running.

    In my exit button I have:

    Unload Form1
    Set Form1 = Nothing

    Does this clear it from the memory??

    Any info,

    Thanks

    Mark

  2. #2
    Join Date
    Nov 2002
    Posts
    86
    Depends what you are doing. If you have a recordset open possibly its not closing at all. or a database connection. Perhaps you have a timer object still running (though i'm pretty sure they die when the form is unloaded).

    One thing to do that i can't see you doing there is...

    in your cmdExit_click put the following

    Unload Me

    In your form1_unload event put

    Set form1 = nothing

    see how that goes. Don't have any code after the unload me in cmdExit. If you have to make sure you have Exit Sub after it like this

    Unload Me
    Exit Sub

  3. #3
    Join Date
    Dec 2001
    Posts
    6,332
    by referencing form1 after the unload, it recreates it, so don't do that. Instead, do this:

    Unload Me
    End

    That should do it, but depending on other objects, you may have to take other steps.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  4. #4
    Join Date
    Nov 2002
    Posts
    86
    Set form1 = nothing
    doesn't actually recreate it. It actually just unreferences it freeing up the memory it took. Just a bit of garbage collection.

    Don't ever use the End statement. This is not the way to end a program. End will cause the program to terminate and it may not unload properly or clean up after itself properly. This can cause more problems than its worth.

    End will more than likely stop your thing in the Task list, but it may cause other problems along the way.

  5. #5
    Join Date
    Dec 2001
    Posts
    6,332
    That's true what you say about End, but that is why I would only use it AFTER the unload. I only had one case so far that required it, and it worked well as I described. Still, I don't really like using it either, but it sounds like it may be needed here.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  6. #6
    Join Date
    Aug 2002
    Posts
    14
    Yes WizBang is right. I had the same problem as you and when I did the:

    Unload Me
    End
    No more problems!

  7. #7
    Join Date
    Nov 2002
    Posts
    86
    I'll agree its a quick fix, but better would be to find out whats causing the problem and fix that, rather than just kill the thing.
    Thats what i reckon anyway

  8. #8
    Join Date
    Aug 2002
    Posts
    14
    Yes it is a quick fix, but I did all the forms with the Unload and it would still show the program in the task menu. Each form had an exit with Unload Me and just to be sure I had the Mian form also with the Unload for each form. Didn't close the program all the time and have no clue why so I ended up with the (End) in the Main form. I had DoEvents on one of the other forms and thought the Unload Me on the exit would work for that form.

  9. #9
    Join Date
    Apr 2001
    Location
    ohio
    Posts
    300

    unload problem

    i had the same problem.

    use this when exiting:


    Dim frm As Form

    Close
    For Each frm In Forms
    Unload frm
    Next frm


    also, if you run a for-next loop, be SURE to "exit for" instead of jumping out


    xp was bad about not closing, i use the above code and i always

    Exit For

  10. #10
    Join Date
    Oct 2002
    Location
    India
    Posts
    103

    Hi everyone

    Everyone seems to be discussing this problem accept mark.

    Why is MARK not answering to these many replies

    But according to me using END would stop all the processes with the applications like timers, recordsets, Connections.

    Offcourse u never know whether all processes related to the app are been killed or not

    But END never created a problem in my applications

    Still to be more if we want dont wanna rely on the system, the better solutions is to kill all the active connections and timers running thru code

    that would be a better option

    we can just write a procedures in which we will kill all the active connections and timer or any other possible process that relating to the application, and can call this Procedure when we want to close the app

    GOODLUCK
    Nilesh
    Pune, Maharashtra
    India

  11. #11
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    Here is two interestings threads that talk about END and how to end a program correctly

    http://www.codeguru.com/forum/showth...hreadid=217655

    http://www.codeguru.com/forum/showth...hreadid=206561

    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  12. #12
    Join Date
    Mar 2002
    Location
    United Kingdom
    Posts
    60
    Hello again,

    10 Replies!!!

    Got it working now, I just used:

    Unload Me
    End

    Thanks for the Info.

    Mark
    Last edited by Mark2; December 5th, 2002 at 01:26 PM.

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

Featured