DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Problems Unloading a Form

  1. #1
    Join Date
    Apr 2004
    Location
    Hawaii
    Posts
    220

    Question Problems Unloading a Form

    WinXP/VB6. I can't seem to get 'Unload Me' to work when my App is processing code beneath a command button. For example, the user clicks a command button on Form1 whose code calls several related SUBs:

    Private Sub Command1_Click()

    Call Sub1()
    Call Sub2()
    (in sub 2)...................Load Form2
    .................................Unload Me
    .................................(control continues on???)
    Call Sub3()

    End Sub

    I want the option to load a new form (Form2) from the Sub2() code in Form1 and immediately stop all processing in Form1 without another line of code being read. I THOUGHT I could accomplish this by simply unloading Form1 when I reached this point, but I have found that Form1 will continue to process code (past 'Unload Me') until it reaches the end of all code beneath the Command1 button (apparently reloading the form to do so).

    I have the sick feeling I'm using bad coding practices. Can someone confirm this? Is there a proper way to stop the current form from processing another line of code from a stated point and unload it immediately? Do I need to clear some reference somewhere?

    Frustrated ... any help, advice, suggestions appreciated.

    Shannon

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    I don't think you can use Unload to instantly stop all processing in a form. I would create a form-level flag (e.g., UnloadMe) and set it to True when you want to unload the form. Then check the value of the flag after each statement and only execute the next statement if the flag is False:
    Code:
    Option Explicit
    Private UnloadMe As Boolean
    
    Private Sub cmdButton_Click()
        Call Sub1
        If Not UnloadMe Then Call Sub2
        If Not UnloadMe Then Call Sub3
        If UnloadMe Then Unload Me
    End Sub
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    just put a

    Exit Sub

    after the Unload Me stetement:

    Unload Me
    Exit sub
    "There are two ways to write error-free programs. Only the third one works."
    Unknown

  4. #4
    Join Date
    Apr 2004
    Location
    Hawaii
    Posts
    220
    Okay, then Phil, can I assume then that all active SUBs must then complete their code before a form will be unloaded, even after the 'Unload Me' command has been issued?

    And maybe more important, does this mean I am not necessarily using sloppy coding practices, I likely just need to move things around a bit?

    It's been a long day, I think I'm mumbling ... thanks for help (and you too Marco).

    Shannon

  5. #5
    Join Date
    Oct 2005
    Location
    Maady
    Posts
    1,819
    put in
    form2_load()
    unload form1
    ....
    call sub3()
    ....
    end sub
    Programmer&Cracker CS
    MyBlog:Blog.Amahdy.com
    MyWebsite:www.Amahdy.com

  6. #6
    Join Date
    Feb 2007
    Posts
    9
    Just open the form as acDialog,
    This property will stop the exec. of the current sub, till form2 is loaded.

Similar Threads

  1. A form passing a parameter to another form
    By Bill Gaddam in forum VB Classic
    Replies: 10
    Last Post: 11-06-2007, 12:15 PM
  2. Replies: 1
    Last Post: 01-12-2006, 07:53 PM
  3. Replies: 1
    Last Post: 06-14-2002, 03:49 PM
  4. HELP!! ADO .Editmode Property Problems HELP!!
    By Matt Goyak in forum VB Classic
    Replies: 0
    Last Post: 04-10-2002, 09:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center