-
Sep 13th, 2017, 10:13 AM
#1
Thread Starter
Member
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?
-
Sep 13th, 2017, 10:19 AM
#2
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.
-
Sep 13th, 2017, 10:29 AM
#3
Thread Starter
Member
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.
-
Sep 13th, 2017, 10:30 AM
#4
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
-
Sep 13th, 2017, 01:05 PM
#5
Re: Problem with closing forms.
Originally Posted by ams16
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
-
Sep 13th, 2017, 01:41 PM
#6
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.
-
Sep 13th, 2017, 11:34 PM
#7
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
-
Sep 14th, 2017, 12:34 AM
#8
Re: Problem with closing forms.
Originally Posted by ams16
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
-
Sep 14th, 2017, 12:36 AM
#9
Re: Problem with closing forms.
ams16,
Do you know how to attach a zip of your project ?
-
Sep 14th, 2017, 01:21 AM
#10
Re: Problem with closing forms.
Originally Posted by Elroy
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.
-
Sep 14th, 2017, 09:02 AM
#11
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.
-
Sep 15th, 2017, 04:31 PM
#12
Thread Starter
Member
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
-
Sep 15th, 2017, 04:38 PM
#13
Re: Problem with closing forms.
FormMain is not in the zip
-
Sep 15th, 2017, 04:39 PM
#14
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.
-
Sep 15th, 2017, 04:40 PM
#15
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.
-
Sep 15th, 2017, 04:41 PM
#16
Thread Starter
Member
Re: Problem with closing forms.
I imported FormMain to my project from the folder called Api Mikrotik
-
Sep 16th, 2017, 06:41 AM
#17
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
-
Sep 16th, 2017, 03:44 PM
#18
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.
-
Sep 16th, 2017, 03:52 PM
#19
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.
-
Sep 16th, 2017, 05:43 PM
#20
Re: Problem with closing forms.
well, I guess that 'ENDS' this discussion (at least I HOPE it Does!) ~smile~
-
Sep 17th, 2017, 02:57 PM
#21
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|