How to unload after a Close?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Harry J. Smith

    How to unload after a Close?

    I have written a Visual Basic program that does a long calculation and
    writes the results to disk as it runs. If I click the Close button the
    window closes but the program keeps running. How can I get the program
    to recognize that its window has been closed and quit running?

    -Harry http://home.netcom.com/~hjsmith



  • Kris

    #2
    Re: How to unload after a Close?

    > If I click the Close button the[color=blue]
    > window closes but the program keeps running. How can I get the program
    > to recognize that its window has been closed and quit running?
    >
    > -Harry http://home.netcom.com/~hjsmith[/color]

    Harry,
    I don't consider myself a VB expert but I think your problem is
    rather simple. When you click your "Close" button, you're only
    closing the Form but not unloading it from memory.
    There exists an "Unload" event for a Form. In your Sub
    Close_Click() event, you need to call the Unload event. This will
    unload your Form from memory.

    Private Sub cmdClose_Click( )
    Unload Me 'or use the name of your Form in place of
    Me
    End Sub

    Or, if you want to completely quit the program by clicking your Close
    button try this(after Saving all necessary data, of course):

    Private Sub cmdClose_Click( )
    End
    End Sub

    Hope this helps.

    Peace,

    Kris

    Comment

    • Bob Butler

      #3
      Re: How to unload after a Close?

      "Kris" <kpa1964@yahoo. com> wrote in message
      news:6bacb495.0 309091652.b7948 53@posting.goog le.com[color=blue][color=green]
      >> If I click the Close button the
      >> window closes but the program keeps running. How can I get the
      >> program to recognize that its window has been closed and quit
      >> running?
      >>
      >> -Harry http://home.netcom.com/~hjsmith[/color]
      >
      > Harry,
      > I don't consider myself a VB expert but I think your problem is
      > rather simple. When you click your "Close" button, you're only
      > closing the Form but not unloading it from memory.
      > There exists an "Unload" event for a Form. In your Sub
      > Close_Click() event, you need to call the Unload event. This will
      > unload your Form from memory.
      >
      > Private Sub cmdClose_Click( )
      > Unload Me 'or use the name of your Form in place of
      > Me
      > End Sub[/color]

      Unload Me is best since it is more generic; if you ever create multiple
      instances of the form you don't have to recode
      [color=blue]
      > Or, if you want to completely quit the program by clicking your Close
      > button try this(after Saving all necessary data, of course):
      >
      > Private Sub cmdClose_Click( )
      > End
      > End Sub[/color]

      END is never needed in a VB app and can cause harm if used improperly; the
      general rule of thumb is NEVER use it. VB apps terminate when no code is
      running and all forms are unloaded.

      Comment

      • Kris

        #4
        Re: How to unload after a Close?

        >"Bob Butler" <tiredofit@nosp am.com> wrote in message news:<u1v7b.147 55>[color=blue]
        >
        > END is never needed in a VB app and can cause harm if used improperly; the
        > general rule of thumb is NEVER use it. VB apps terminate when no code is
        > running and all forms are unloaded.[/color]

        Thanks for your input, Bob. I'm always learning new things. Since I
        wasn't aware of this about the "End" statement, in your opinion, what
        is the best way to quit a desktop application upon clicking an Exit
        (command) button?

        Thanks,

        ~kris

        Comment

        • Kris

          #5
          Re: How to unload after a Close?

          kpa1964@yahoo.c om (Kris) wrote in message[color=blue]
          > Since I wasn't aware of this about the "End" statement, in your opinion,
          > what is the best way to quit a desktop application upon clicking an Exit
          > (command) button?
          >[/color]

          Don't bother replying to this thread. I found a really nice summary
          of the "End" statement in an archive on this list.

          See: Subject: Notes on VB 'End' Statement [was Re: X to exit ]
          From: Rob Strover (dislexic_wobma t.NOSPAM@yahoo. com)
          Date: 2002-11-14 08:32:10 PST

          ~kris

          Comment

          • Harry J. Smith

            #6
            Re: How to unload after a Close?

            Thanks for your help.

            I did not see how to add cmdClose_Click to my code.

            I read an earlier post and figured it out from there. I already had a
            quit flag so the new code was:

            Private Sub Form_QueryUnloa d(cancel As Integer, unloadmode As Integer)
            mbQuit = True
            End Sub

            In the main loop of the program I added:

            If mbQuit Then Unload Me: oFormOwner.Show : Exit Sub

            This worked great for me.

            -Harry


            "Bob Butler" <tiredofit@nosp am.com> wrote in message
            news:u1v7b.1475 5$QT5.5892@fed1 read02...[color=blue]
            > "Kris" <kpa1964@yahoo. com> wrote in message
            > news:6bacb495.0 309091652.b7948 53@posting.goog le.com[color=green][color=darkred]
            > >> If I click the Close button the
            > >> window closes but the program keeps running. How can I get the
            > >> program to recognize that its window has been closed and quit
            > >> running?
            > >>
            > >> -Harry http://home.netcom.com/~hjsmith[/color]
            > >
            > > Harry,
            > > I don't consider myself a VB expert but I think your problem is
            > > rather simple. When you click your "Close" button, you're only
            > > closing the Form but not unloading it from memory.
            > > There exists an "Unload" event for a Form. In your Sub
            > > Close_Click() event, you need to call the Unload event. This will
            > > unload your Form from memory.
            > >
            > > Private Sub cmdClose_Click( )
            > > Unload Me 'or use the name of your Form in place[/color][/color]
            of[color=blue][color=green]
            > > Me
            > > End Sub[/color]
            >
            > Unload Me is best since it is more generic; if you ever create[/color]
            multiple[color=blue]
            > instances of the form you don't have to recode
            >[color=green]
            > > Or, if you want to completely quit the program by clicking your[/color][/color]
            Close[color=blue][color=green]
            > > button try this(after Saving all necessary data, of course):
            > >
            > > Private Sub cmdClose_Click( )
            > > End
            > > End Sub[/color]
            >
            > END is never needed in a VB app and can cause harm if used improperly;[/color]
            the[color=blue]
            > general rule of thumb is NEVER use it. VB apps terminate when no code[/color]
            is[color=blue]
            > running and all forms are unloaded.
            >[/color]


            Comment

            Working...