How to close a VB6 exe?

Discussion in 'AutoCAD' started by tothpal, Nov 11, 2004.

  1. tothpal

    tothpal Guest

    Hi,

    I wrote a simple form exe to AutoCAD 2002. How can I close the program clicking the upper right corner "x" button?
    I do not why, but now when i click to the upper right corner "x" button, the form become hidden and the exe still running.
    Can anybody help me?

    Paul
     
    tothpal, Nov 11, 2004
    #1
  2. tothpal

    Jürg Menzi Guest

    Hi Paul

    Use 'Form_Terminate' event...

    Cheers
     
    Jürg Menzi, Nov 11, 2004
    #2
  3. tothpal

    tothpal Guest

    Hi,Juerg

    I have tried this but the close button still not close the program just hide the form.
    Private Sub Form_Terminate()
    End
    End Sub

    I have made a Command button and it close the exe.
    Private Sub Command1_Click()
    End
    End Sub

    Should I set something in form properties to make the close button exit my program?

    Paul
     
    tothpal, Nov 11, 2004
    #3
  4. tothpal

    GTVic Guest

    You don't need any specific code to make the X button work.

    Do you have some specific code that minimizes or hides the window?

    Did you put anything in the Form_QueryUnload event. If you set the Cancel value to something other than zero then the app will not quit.

    You could put some code in all the events that fire when the app is closing (Unload, QueryUnload, Terminate, Deactivate) and put break points on them and then trace through the sequence when you click the close button. Compare the result with an application where the X button works.

    Typically this problem happens when some code is still executing at the time the application is trying to quit (like some code in a LostFocus event).

    Greg
     
    GTVic, Nov 11, 2004
    #4
  5. tothpal

    antmjr Guest

    I’m referring to the paragraph “Beware the One Form†of Rod Stephens’s “Bug proofing Visual Basicâ€, just to suggest you a possible cause

    he says: “when you define a form named MyForm, VB creates a template that you can use to make any number of forms of this type†as in: Set frm = New MyForm

    “VB also creates a single special instance of the type MyForm that has the name MyForm†i.e. there are 2 MyForm + your code instance frm : MyForm template, MyForm special instance made by VB and your personal instance frm

    A code like the following

    Dim frm as MyForm
    Set frm = New MyForm
    MyForm.Caption = “abcâ€
    frm.show

    “sets the caption for the special instance named MyForm instead†of frm and “as if this were not confusing enough, this code has also realized two copies of the form: one referenced by the frm variable and the original form named MyForm. If you close all of the visible forms after running this code, the special form named MyForm will still be running, even though it was never displayed.â€

    He explains some other problems, which can be avoided by using “Me.“ instead of “MyForm.†whenever possible
     
    antmjr, Nov 11, 2004
    #5
  6. tothpal

    SpeedCAD Guest

    SpeedCAD, Nov 11, 2004
    #6
  7. I always unload all my forms(objects) when done
    Might be overkill in the Unload event but...I know
    it's dead...

    Unload Form1
    Unload Form2
    ect....
     
    Paul Richardson, Nov 11, 2004
    #7
  8. tothpal

    tothpal Guest

    Thanks a lot all of you!

    I have tried all what you suggested and the

    Private Sub Form_Unload()
    End
    End Sub

    works fine, the program exit.

    Paul
     
    tothpal, Nov 11, 2004
    #8
  9. Be sure to set your acad application object to nothing
    in that same event.

    Private Sub Form_Unload()
    Set acadapp = nothing
    end sub.
     
    Jorge Jimenez, Nov 11, 2004
    #9
  10. tothpal

    GTVic Guest

    IMHO, if you have to put an END statement in then there is something wrong with another part of your code. In the long run I think you would benefit from figuring out what that is.
     
    GTVic, Nov 13, 2004
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.