Results 1 to 21 of 21

Thread: Problem with closing forms.

  1. #1

    Thread Starter
    Member
    Join Date
    May 2017
    Posts
    39

    Question Problem with closing forms.

    Hello! I am programming an application in visual basic 6 with three forms. ,each form has an specific button to open the rest of the forms.

    However, I have problems when I want to close the form3. When I close this form, all the application is closed. How can I do to only close that form when I press the close button?

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,855

    Re: Problem with closing forms.

    Ams16,

    Your explanation is a bit confusing, but I can tell you how a VB6 program decides to exit.

    Once all your code has completed execution (and returned control back to the Windows OS), and also, all your forms have been unloaded, your program will exit.

    Now, here's a caveat. If your code has finished executing, and you have a form hidden (but still loaded), you can be in a situation where your program will not exit, but it doesn't have any user-interface showing. But that's sort of the opposite of what you're describing.

    In your situation, it seems that you're unloading all your forms.

    Good Luck,
    Elroy

    EDIT1: The only other (obvious) way I can think of for a VB6 program to exit is to execute an "End" statement. However, that is known to be terribly bad programming practice.

    EDIT2: If you wish to have a program that (possibly temporarily) has no user interface, create a form that is loaded-but-hidden. And then, only unload that form when you're truly ready to exit.
    Last edited by Elroy; Sep 13th, 2017 at 10:23 AM.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2017
    Posts
    39

    Re: Problem with closing forms.

    Hello Elroy.

    My problem is:

    I open three formularies in my application (the three forms are opened)

    When I try to close form1, only form1 is closed. That is OK.
    When I try to close form2, only form2 is closed. That is OK.
    When I try to close form3, then form1, form2 and form3 are closed. That is the problem. I only want to close form3 in this case.

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Problem with closing forms.

    Is it possible that you're doing something in the closing of that form3 that's causing the application to exit? w/o seeing how you are creating/showing the forms, and closing them, it's hard to say what it might be. Elroy gave the most obvious and logical explanations. There could be a couple others though.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: Problem with closing forms.

    Quote Originally Posted by ams16 View Post
    However, I have problems when I want to close the form3. When I close this form, all the application is closed. How can I do to only close that form when I press the close button?
    It would help if you would post the pertinent code snippet showing where this happens.

    Spoo

  6. #6
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,855

    Re: Problem with closing forms.

    ams16,

    With relation to other forms, there's nothing special about any particular form. If you close a particular form, it's not going to try and do anything to any other form(s). And, this is true, regardless of what your start-up form is. In fact, there's nothing really special about the start-up form either, other than it gets automatically loaded when the project starts. But it's not special in any other way.

    There are a couple of exceptions I can think of. One would be a project that used MDI forms. For instance, if your Form3 is an MDI form, and Form1 and Form2 are its children, then closing Form3 would also close Form1 and Form2. But I really don't think that's what you're saying.

    Another exception would be modal forms. However, these can't be used to produce the situation you describe. Modal forms just prevent further up-stream forms from getting the focus. They don't auto-close any other forms.

    Another exception, which I highly doubt, would be if you're playing around with the SetParent API call. You could build a situation that was as you describe with calls to this SetParent function. However, I highly doubt that's what's happening.

    The only thing left (that I can think of is), in your Form3, you're executing some code that's closing Form1 and Form2. Or, you're executing an "End" statement in Form3. Or, and also VERY unlikely, you're executing some WMI code that's doing a project "kill", similar to task manager.

    If you'd show us the code in Form3, I'd bet that we could tell you the problem in about 10 seconds.

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  7. #7
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Problem with closing forms.

    Make a copy of your project.
    If you wish to avoid sharing some of your code(etc), then trim/remove as much as you want, but leave enough to demonstrate your problem.
    Zip and attach that copy for us, so we can get our teeth into it.

    Rob

  8. #8
    Frenzied Member
    Join Date
    Jun 2014
    Posts
    1,084

    Re: Problem with closing forms.

    Quote Originally Posted by ams16 View Post
    Hello! I am programming an application in visual basic 6 with three forms. ,each form has an specific button to open the rest of the forms.

    However, I have problems when I want to close the form3. When I close this form, all the application is closed. How can I do to only close that form when I press the close button?
    example
    a program with 3 forms and a module
    start-up object is Sub Main

    code in the module:
    Code:
    Sub Main()
        Form1.Show
        Form2.Show
        Form3.Show
    End Sub
    code in form1
    Code:
    Private Sub Command1_Click()
        Form2.Show
        Form3.Show
    End Sub
    code in form2
    Code:
        Form1.Show
        Form3.Show
    code in form3
    Code:
        Form1.Show
        Form2.Show
    thats it.
    program only ends when all 3 forms are closed
    so, if your program ends when form3 closes (and 1 of the other forms is still shown)
    then there is something in form3 that makes the program end
    (and that is what everyone is trying to tell you)
    do not put off till tomorrow what you can put off forever

  9. #9
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Problem with closing forms.

    ams16,
    Do you know how to attach a zip of your project ?

  10. #10
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,121

    Re: Problem with closing forms.

    Quote Originally Posted by Elroy View Post
    With relation to other forms, there's nothing special about any particular form. If you close a particular form, it's not going to try and do anything to any other form(s).
    Forms can have owner form which keeps owned forms z-order above their owner's one. And here comes the shocker: when owner is closed it automagically closes owned forms (kind of like MDI).

    So, yes, if you have this code in Form3
    Code:
    Private Sub Command1_Click()
        With New Form1
            .Show OwnerForm:=Me
        End With
        With New Form2
            .Show OwnerForm:=Me
        End With
    End Sub
    ... closing Form3 unloads all owned forms too and the process actually terminates.

    cheers,
    </wqw>
    Last edited by wqweto; Sep 14th, 2017 at 04:42 AM.

  11. #11
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,855

    Re: Problem with closing forms.

    Ahhhh, wqweto, good catch. I seldom use that, but I did know it was an option.

    I suspect that's the same thing as using SetParent, but I haven't explicitly tested that with GetParent.

    I'd be surprised if that's his problem, but who knows.

    Best Regards,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  12. #12

    Thread Starter
    Member
    Join Date
    May 2017
    Posts
    39

    Exclamation Re: Problem with closing forms.

    I attack the Zip with my project. The project is TFG.vbp
    It includes an API form called FormMain. The problem is with that form.
    Thank you!!Project.zip

  13. #13
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Problem with closing forms.

    FormMain is not in the zip

  14. #14
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,855

    Re: Problem with closing forms.

    ams ams ams.


    You didn't give us enough to actually load the project, but I opened your FormMain in Notepad++ and spotted the problem right away. Here's the Form_Unload event...

    Code:
    
    Private Sub Form_Unload(Cancel As Integer)
        bErr = True
        ws.Close
        End
    End Sub
    
    I should just let you stare at that code and figure it out. Tsk tsk tsk. Several of us outlined the problem in posts above.












    Ok ok, see that "END" statement on a line by itself? That's VERY bad. You should NEVER do that. A stand-alone END will shut down your program. I heard one person describe it as a Mack Truck going down the interstate highway, and the driver snatches the keys out of the ignition and throws them out the window. NOT good.

    Take Care,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  15. #15
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,855

    Re: Problem with closing forms.

    DataMiser, It's in the Api Mikrotik folder.
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  16. #16

    Thread Starter
    Member
    Join Date
    May 2017
    Posts
    39

    Re: Problem with closing forms.

    I imported FormMain to my project from the folder called Api Mikrotik

  17. #17
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: Problem with closing forms.

    Elroy

    You rascal ..

    Here's the Form_Unload event...

    Code:
    
    Private Sub Form_Unload(Cancel As Integer)
        bErr = True
        ws.Close
        End
    End Sub
    
    I should just let you stare at that code and figure it out. Tsk tsk tsk. Several of us outlined the problem in posts above.











    Yup. You got me.
    Your clever use of blank lines had me hanging, staring at the End statement, wondering, well, what's so bad with that?
    (Yes, I don't use it, but I didn't know the answer, either)

    Then (drum roll), I mouse-wheeled down and ..voila

    BTW, what's worse than a Mack Truck going down the interstate highway, and the driver snatches the keys out of the ignition and throws them out the window?













    A RoboDrive Mack Truck.

    Spoo

  18. #18
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,855

    Re: Problem with closing forms.

    *laughs at Spoo*

    But I do think that's coming, 10 years max I'd say. Congress passed some bill last week setting federal standards for auto-drive vehicles. Personally, trucks on the interstate (but with a driver/person still in the cab), I'd think that would be something they could get right. Driving on the low-roads may be a different story though. I can see it now, 10 mile long truck caravans, all equally spaced and staying in the right lane, and with enough space for cars to get between them for on-off ramps. Works for me.

    Take Care,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

  19. #19
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: Problem with closing forms.

    Elroy

    all equally spaced and staying in the right lane, and with enough space for cars to get between them for on-off ramps.
    Hadn't thought it through, but that WOULD be something to strive for.

    EDIT-1

    Re post #20 .. YES, Sammi .. sorry about the OT contortions.

    Spoo
    Last edited by Spooman; Sep 17th, 2017 at 12:09 AM.

  20. #20
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    9,145

    Re: Problem with closing forms.

    well, I guess that 'ENDS' this discussion (at least I HOPE it Does!) ~smile~

  21. #21

    Thread Starter
    Member
    Join Date
    May 2017
    Posts
    39

    Re: Problem with closing forms.

    Problem solved!

    I delated the function that Spooman said and now my app works as I want

    Thank you so much

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