Results 1 to 11 of 11

Thread: Is there a better code to use to ensure that every frm in my program is unloaded?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    25
    Is there a better code to use to ensure that every frm in my program is unloaded?

    I have seen a code that I can place in a Module and call that Public sub from within every form's Unload. Does it work and what is that code?

    I have a rather large program that when it is closed VB still shows that it is running. From what I can see, every form has a:

    "Unload me"
    "frmBlahBlah.Show"
    Etc...Ect...

    What is my problem do you think?
    Any ideas or suggestion are greatly welcomed,
    Darkcloud

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I think your problem is that you have not organized your code enough (I don't know cuz I haven't seen your project yet but I have my thoughts). Post some of your Unload events and we'll see

  3. #3
    Lively Member
    Join Date
    Nov 1999
    Posts
    98
    in every form in your project you should have in the Form_Unload() sub the End event:

    Private Form_Unload()
    'terminate the program
    End
    End Sub

    or you can do something like everywhere you have the user manually closing the program by clicking a command button you unload all the forms:

    Private cmdExit_Click()
    Unload Form1
    Unload Form2
    .
    .
    etc...

    'terminate the program
    End
    End Sub

    i don't know if that's exactly what you were looking for but i hope it helps nonetheless. take care.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    25

    Kedaman ---

    Kedaman,

    Naturally every cmdExit() is performed as each page passes to another form. At no time is there ever two forms open at once. Basically one unloads as the next form Shows...Is this an accurate way to do it?

    Private Sub cmdExit_Click()
    Unload Me
    frm1.Show
    End Sub

    Private Sub cmdExit_Click()
    Unload Me
    frm2.Show
    End Sub

    Private Sub cmdExit_Click()
    Unload Me
    frm3.Show
    End Sub

    Private Sub cmdExit_Click()
    Unload Me
    End Sub

  5. #5
    New Member
    Join Date
    Aug 1999
    Location
    Mercer, Wi, US
    Posts
    3
    Darkcloud...

    You may want to check your code in your program to make sure that in one of your other forms doesnt call a variable/function/sub from whatever form is staying open(one of the problems with using globals). You may have closed the form, but if you access a sub/function from it later on, the form is reloaded.. but not shown.. so you need to unload it again.

    Hope this helps..

    Also are you using 'Set frmName=Nothing' ? Usually good practice.

    Kon

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    25

    Kon...

    Kon,

    No I am not using "Set frmName=Nothing", what advantage, exactly will setting the form's name to nothing provide to my program?

    Thankyou for your information,
    Darckloud

  7. #7
    Junior Member
    Join Date
    Jun 1999
    Location
    seattle, wa
    Posts
    23
    You should unload a form as soon as you no longer need it. If one is not unloading, you should be able to identify it by running the code below immediately prior to ending the application. (Note that I have not run this for your purpose however it is similiar to something else i was doing). You could also create a form with a timer and a listbox which every xxx seconds reloades the list box with active forms.

    Just an idea.

    Dim x As Integer

    For x = 0 To Forms.Count - 1
    msgBox Forms(x).Caption & " is still loaded"
    next X

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    25

    Do you all think that this would be efficient?

    Do you all think that this would be efficient?

    We are talking my proggy has over 40 forms, so what if I add a Module with a Public sub like the following, and have each cmdExit_Click() make a call to the Module's Sub.

    Public Sub
    Unload frm1
    Unload frm2
    Unload frm3
    Unload frm4
    Unload frm5
    ....and so on

    What say you?

  9. #9
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    The best way to achieve this is to use Forms collection.
    Code:
    Dim frm As Form
    
    For Each frm In Forms
        Unload frm
    Next

  10. #10
    Lively Member
    Join Date
    May 1999
    Location
    flanders, nj 07836
    Posts
    110

    wow

    Wow! I can't believe that it took 8 postings to get a descent answer for that question. Nice job serge!

  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    This problem has once again been solved!

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