Results 1 to 16 of 16

Thread: App Close?

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member Emo's Avatar
    Join Date
    Jul 2000
    Posts
    428

    Question

    Hello,
    I just have a quick quesion about closing an application...
    How can I make it so when I hit a command button, it closes all forms in my project, not just the one that has the command button?
    Thanks for your help!
    -Emo
    -=VB6 Enterprise Edition=-
    -=VC++6Enterprise Edition=-
    «¤E³m°O²™¤»

  2. #2
    Lively Member
    Join Date
    Jul 2000
    Posts
    94
    Code:
    Private Sub Command1_Click()
    dim x as form
    for each x in forms
    unload x
    set x = nothing
    next x
    end sub
    [Edited by CthulhuDragon on 08-31-2000 at 05:33 PM]

  3. #3
    Guest
    Use this:

    Code:
    Public Sub UnloadAllForms()
        Dim OfTheseForms As Form
    For Each OfTheseForms In Forms
    Unload OfTheseForms
    Set OfTheseForms = Nothing
    Next OfTheseForms
    End Sub
    
    Usage:
    
    Call UnloadAllForms

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    For i = 0 to Forms.Count-1
        Unload Forms(0)
    Next i
    Heh. My 3-liner beats yours!
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Lively Member
    Join Date
    Jul 2000
    Posts
    94

    Talking

    I won! I was the fastest by a whole minute!

  6. #6
    Guest
    parksie, it is best if you Set each form to nothing. It will free up any resources that the form is using. CthulhuDragon, you have Set x = nothing at after the Next, so it will set the last form to nothing, not every form. And an End statement can be added after next.

    Code:
    Public Sub UnloadAllForms()
    Dim OfTheseForms As Form
    For Each OfTheseForms In Forms
    Unload OfTheseForms
    Set OfTheseForms = Nothing
    Next OfTheseForms
    End
    End Sub

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Parksie:
    You don't win..you didn't set the forms = nothing
    which is not necessary but good programming practice.

    Least ways, that's what I was told.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    If you close all the forms then your app will end, therefore automatically freeing the resources. Anyway - the resources are freed when the form is unloaded.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    Lively Member
    Join Date
    Jul 2000
    Posts
    94
    Actually since the app is closing it doesn't matter all that much. It really only makes a difference when the app is going to be around for a while eating up resources. But habit prevails.

  10. #10
    Guest
    Originally posted by CthulhuDragon
    Code:
    Private Sub Command1_Click()
    dim x as form
    for each x in forms
    unload x
    next x
    set x = nothing
    end sub
    The line Set X = Nothing should come before the line Next X, otherwise it's not in the loop.

  11. #11
    Lively Member
    Join Date
    Jul 2000
    Posts
    94
    Megatron - I know it was a typo.

  12. #12
    Guest
    As HeSaidJoe said, you don't have to use it, but it's a good habit.

    Unload Me won't always free up resources, so you should really use Set form = Nothing to free up those few resources that are running.

    And parksie, code fix:

    Code:
    For i = 0 to Forms.Count-1
        Unload Forms(i) 'for i(index) = 0 to forms.count, you have 0 :)
    Next i

  13. #13
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    ...and the beat goes on...

    Later
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  14. #14
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Actually, if you keep it at Forms(0), it will unload the next form - since when you unload a form, it removes it from the collection. Therefore Forms(0) will cycle through them all .
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  15. #15
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Agreed, if your forms were an array then i would be the correct index but since it's a collection i would never work.
    Now, this thread is officially dead! Least we hope so
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  16. #16
    Guest
    Originally posted by Matthew Gates
    As HeSaidJoe said, you don't have to use it, but it's a good habit.

    Unload Me won't always free up resources, so you should really use Set form = Nothing to free up those few resources that are running.

    And parksie, code fix:

    Code:
    For i = 0 to Forms.Count-1
        Unload Forms(i) 'for i(index) = 0 to forms.count, you have 0 :)
    Next i
    When WM_DESTROY and WM_NCDESTROY are set to the window, they will automatically free up resources. Using the statement Set Form = Nothing is simply a process of double checking.

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