|
-
June 20th, 2001, 10:27 AM
#1
VB question
I'm taking a VB course and just got into multiple forms. DUring the course of my project, I had to close the program from the current form.
My question is this: " Is there an action associated with the 'X' box in the Window controls where I can issue unload commands for all forms resident in memory?"
I posed this same question to my instructor and he just scratched his head and grinned. Then stated that there was no such action without creating an exit button with the unload commands in it. Doesn't make sense since there is the Form_load event it would stand to reason that a Form_Unload action or something similar would be available.
Thanks for any help.
Stress.... The uncontrollable urge to choke the living $417 out of someone who desperately needs it.
Ignorance.... The inherent capacity to demand of someone else that which one is too lazy to learn/perform for one's self.
User....An individual who, through immense proportions of ignorance, create stress.
-
June 20th, 2001, 10:47 AM
#2
Registered User
There is exactly a Sub Form_Unload. This is an event that runs when the form closes. You could write a simple routine that whenever any form unloads, it unloads all other forms.
Not sure if this is what you were looking for, but let me know if I can help more.
-
June 20th, 2001, 11:11 AM
#3
Originally posted by Deity:
<STRONG>There is exactly a Sub Form_Unload. This is an event that runs when the form closes. You could write a simple routine that whenever any form unloads, it unloads all other forms.
Not sure if this is what you were looking for, but let me know if I can help more.</STRONG>
That is <STRONG>exactly</STRONG> what I was looking for. Could you tell me how to invoke it? I tried tools --> Add Procedure Sub --> and named the procedure as Form_Unload When that didn't work for me, I also tried naming it to Form_Close
Is there a certain level of VB that I need for some of these functions (professional perhaps)?
Thanks for verifying that I'm not crazy <IMG SRC="smilies/tongue.gif" border="0">
-
June 20th, 2001, 12:30 PM
#4
Registered User
The Form_Unload is a built-in event of the object. I'm assuming you're using MS VB6, and since I don't know the technical names of the location, I'll just describe how you change it. Above your code you have two drop down boxes, the left one lists the objects of the form. One of those objects is the form itself. The right drop down box lists all the events associated with that object. In that drop down list, select Unload. This will automatically create the procedure in your code and you should be able to place whatever code you wish there. I used a similar routine once, in a multiple form project. <IMG SRC="smilies/smile.gif" border="0">
A bored admin is a very dangerous person...
-
June 20th, 2001, 12:49 PM
#5
<STRONG>THANKS!!</STRONG>
-
June 20th, 2001, 01:14 PM
#6
Registered User
Let me know if you are able to get the code to work properly. I'm trying to stay up with my VB code.
-
June 20th, 2001, 01:24 PM
#7
Should be able to tell you tonight when I get home, but I remember the two bars that you referenced and am sure it will work properly once the right channels are created to create skeleton of the procedure.
Thanks again. I'll definitely let you know how it turns out.
-
June 20th, 2001, 02:22 PM
#8
Originally posted by Shift_2_Break:
<STRONG>I'm taking a VB course and just got into multiple forms. DUring the course of my project, I had to close the program from the current form.
My question is this: " Is there an action associated with the 'X' box in the Window controls where I can issue unload commands for all forms resident in memory?"
I posed this same question to my instructor and he just scratched his head and grinned. Then stated that there was no such action without creating an exit button with the unload commands in it. Doesn't make sense since there is the Form_load event it would stand to reason that a Form_Unload action or something similar would be available.
Thanks for any help.</STRONG>
use the End function.
Terminates execution immediately. Never required by itself but may be placed anywhere in a procedure to end code execution, close files opened with the Open statement and to clear variables.
-
June 20th, 2001, 04:09 PM
#9
Thanks for the comment Opiate, but I'd need to enter end in the _unload event in order to successfully complete my project. There is only supposed to be one form with an exit command to terminate the project and I don't believe in leaving items resident in memory because an idiot programmer (me) did not plan for the contingency of someone terminating a form without using a menu or command option given on the form.
Another <STRONG>workaround</STRONG> is to disable the 'x' button on the window frame for all forms and force the user to use only those controls available on the form itself.
Sorry for the confusion and hope that clarifies.
Stress.... The uncontrollable urge to choke the living $417 out of someone who desperately needs it.
Ignorance.... The inherent capacity to demand of someone else that which one is too lazy to learn/perform for one's self.
User....An individual who, through immense proportions of ignorance, create stress.
-
June 20th, 2001, 07:10 PM
#10
Thanks Diety and Opiate. The drop menus set up the procedure and entering end only does the trick for all the forms. I'm (almost) more satisfied that M$ is not ALL bad <IMG SRC="smilies/wink.gif" border="0">
Thanks again.
-
June 20th, 2001, 08:12 PM
#11
Registered User
Good to hear it! Glad I could help. <IMG SRC="smilies/smile.gif" border="0">
-
June 20th, 2001, 11:17 PM
#12
Sample
Create a project exe...
1. create 3 forms:
form1
form2
form3
2. on the first form create a command button:
cmdExit
3. on the first form create menus:
Caption = Menu, Name = mnuMenu
Child Caption = Exit, Name = mnuExit
Caption = Forms, Name = mnuFrm
Child1 Caption = Form2, Name = mnuForm1
Child2 Caption = Form3, Name = mnuForm2
4. Create a Module
here is the code...
5. Form1:
Private Sub cmdExit_Click()
Call UnloadAll
End Sub
Private Sub mnuExit_Click()
Call UnloadAll 'Calls the Public Sub in the Module
End Sub
Private Sub mnuForm2_Click()
Form2.Show
End Sub
Private Sub mnuForm3_Click()
Form3.Show
End Sub
6. Module:
Public Sub UnloadAll() 'Call this public sub on the main form mnuExit and cmdExit.
On Error Resume Next 'An error will occur if you try and close forms that are not open.
' On Error Resume ignores the errors and continues processing code.
Unload Form1
Unload Form2
Unload Form3
End Sub
Hope that helps. This will unload all the forms from the memory.
cheers,
opiate
-
June 21st, 2001, 09:39 AM
#13
Registered User
Opiate -
Here's a scenario for you...in a situation similar to this, using multiple forms, but the number of open forms can vary...would there be a way to close all open forms EXCEPT for the main form. Just curious if there was a way, without having to list each form, like in your example:
Unload Form1
Unload Form2
Unload Form3
Any thoughts?
-
June 21st, 2001, 11:54 AM
#14
Originally posted by Deity:
<STRONG>Opiate -
Here's a scenario for you...in a situation similar to this, using multiple forms, but the number of open forms can vary...would there be a way to close all open forms EXCEPT for the main form. Just curious if there was a way, without having to list each form, like in your example:
Unload Form1
Unload Form2
Unload Form3
Any thoughts?</STRONG>
Try using this in the module and get rid of the list:
Public Sub UnloadAll()
On Error Resume Next
Uload All 'this will close all open forms
form1.show 'this will open your main form
End Sub
-
June 21st, 2001, 12:26 PM
#15
Registered User
That makes sense. Thanks for the info.
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
|
|
Bookmarks