How to completely stop a VB 6 Application-VBForums
Results 1 to 5 of 5

Thread: How to completely stop a VB 6 Application

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    5

    How to completely stop a VB 6 Application

    I wrote a Visual Basic 6 program and included a command button to stop the program

    Below is the code I used to stop the program


    Private Sub cmdStop_Click()
    Unload Me
    End
    End Sub

    The program plays a short wav file every sixty seconds to let the user know it’s still running. Of course it does other stuff too.

    I created an Executable and the command button works fine and completely stops the application. After I click the command button the program disappears from the Task Manage.

    When I click the Red X in the upper right corner the window closes but the task continues running, it doesn’t disappear from the Task Manager and it continues playing the sound file every sixty seconds.

    How do I force a clean completely close?

    Thanks

  2. #2
    VBaholic & Loving It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    GetWindowRect()
    Posts
    11,938

    Re: How to completely stop a VB 6 Application

    Visit the FAQ section at this link. There are at least two topics there that will interest you
    Insomnia is just a byproduct of, "It can't be done"

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum. Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts


    {Alpha Image Control} {Memory Leak FAQ} {GDI+ Classes/Samples} {Unicode Open/Save Dialog} {Icon Organizer/Extractor}
    {VBA Control Arrays} {XP/Vista Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,804

    Re: How to completely stop a VB 6 Application

    if you have a timer to play the waves, you should make it enabled = false
    it is considered very bad practice to use end
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,512

    Re: How to completely stop a VB 6 Application

    Quote Originally Posted by westconn1 View Post
    if you have a timer to play the waves, you should make it enabled = false
    it is considered very bad practice to use end
    If you call the Unload event, doesn't that take care of cleanning up the various objects on the form, like the Timer control?
    Also, I thought the controlbox at the upper right corner would fire the unload event.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,021

    Re: How to completely stop a VB 6 Application

    Quote Originally Posted by krtxmrtz View Post
    If you call the Unload event, doesn't that take care of cleanning up the various objects on the form, like the Timer control?
    Not really... it will unload some things, but you need to stop the Timer control(s) yourself plus various other things, as explained by "How should I close my form/program/class?" FAQ article via LaVolpe's link.
    Also, I thought the controlbox at the upper right corner would fire the unload event.
    It does indeed... which is why cmdStop should only contain Unload Me

    The code to actually close the program (if needed) should be in the Unload event... as explained in the FAQ article I mentioned.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.