VB question
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 19

Thread: VB question

  1. #1
    Registered User
    Join Date
    Aug 2000
    Location
    SoCal USA
    Posts
    210

    Post 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.

  2. #2
    Registered User Deity's Avatar
    Join Date
    Mar 2001
    Location
    Elsewhere
    Posts
    1,412

    Post

    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.

  3. #3
    Registered User
    Join Date
    Aug 2000
    Location
    SoCal USA
    Posts
    210

    Post

    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">

  4. #4
    Registered User Deity's Avatar
    Join Date
    Mar 2001
    Location
    Elsewhere
    Posts
    1,412

    Post

    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...

  5. #5
    Registered User
    Join Date
    Aug 2000
    Location
    SoCal USA
    Posts
    210

    Post

    <STRONG>THANKS!!</STRONG>

  6. #6
    Registered User Deity's Avatar
    Join Date
    Mar 2001
    Location
    Elsewhere
    Posts
    1,412

    Post

    Let me know if you are able to get the code to work properly. I'm trying to stay up with my VB code.

  7. #7
    Registered User
    Join Date
    Aug 2000
    Location
    SoCal USA
    Posts
    210

    Post

    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.

  8. #8
    Registered User
    Join Date
    Oct 2000
    Location
    Kansas City, MO
    Posts
    1,162

    Post

    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.

  9. #9
    Registered User
    Join Date
    Aug 2000
    Location
    SoCal USA
    Posts
    210

    Post

    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.

  10. #10
    Registered User
    Join Date
    Aug 2000
    Location
    SoCal USA
    Posts
    210

    Post

    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.

  11. #11
    Registered User Deity's Avatar
    Join Date
    Mar 2001
    Location
    Elsewhere
    Posts
    1,412

    Post

    Good to hear it! Glad I could help. <IMG SRC="smilies/smile.gif" border="0">

  12. #12
    Registered User
    Join Date
    Oct 2000
    Location
    Kansas City, MO
    Posts
    1,162

    Post

    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

  13. #13
    Registered User Deity's Avatar
    Join Date
    Mar 2001
    Location
    Elsewhere
    Posts
    1,412

    Post

    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?

  14. #14
    Registered User
    Join Date
    Oct 2000
    Location
    Kansas City, MO
    Posts
    1,162

    Post

    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

  15. #15
    Registered User Deity's Avatar
    Join Date
    Mar 2001
    Location
    Elsewhere
    Posts
    1,412

    Post

    That makes sense. Thanks for the info.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •