• 0

[VB6] ending program


Question

4 answers to this question

Recommended Posts

  • 0

Private Sub Form_Unload(Cancel As Integer)
 ? ?MsgBox ("Goodbye")
End Sub

OR

Private Sub Form_Terminate()
MsgBox ("Goodbye")
End Sub

?

Link to comment
Share on other sites

  • 0
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Cancel = 1
    ' Setting the Cancel flag to 1 will stop _
      the Unloading of the form, and since it's _
      the main form it will not end the program.
      
    ' Now you can do whatever you need to do, _
      and then end the program however you want.
      
    ' Note: The UnloadMode flag may be of some _
      interest to you as well.  UnloadMode specifies _
      why the program is ending (the form is closing) _
      and the values are as follows:
      
    ' 0 - vbFormControlMenu - The user chose the Close command _
                              from the Control menu on the form.
    
    ' 1 - vbFormCode        - The Unload statement is invoked from code.
    
    ' 2 - vbAppWindows      - The current Microsoft Windows operating _
                              environment session is ending.
                              
    ' 3 - vbAppTaskManager  - The Microsoft Windows Task Manager is _
                              closing the application.
                              
    ' 4 - vbFormMDIForm     - An MDI child form is closing because the _
                              MDI form is closing.
                              
    ' 5 - vbFormOwner       - A form is closing because its owner _
                              is closing.

    
    ' With this information you can do whatever you need _
      to do, based on how the program is being closed.
      
    ' But in any case, if you interupt the closing by _
      setting the Cancel flag, you need to then close the program.
      
    ' This routine closes all forms and is the best _
      way to end your program.
    If Cancel Then
        Dim f As Form
        For Each f In Forms
            Unload f
            Set f = Nothing
        Next
    End If

End Sub

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.