|
-
Aug 31st, 2000, 04:10 PM
#1
Thread Starter
Hyperactive Member
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²™¤»
-
Aug 31st, 2000, 04:16 PM
#2
Lively Member
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]
-
Aug 31st, 2000, 04:17 PM
#3
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
-
Aug 31st, 2000, 04:18 PM
#4
Monday Morning Lunatic
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
-
Aug 31st, 2000, 04:19 PM
#5
Lively Member
I won! I was the fastest by a whole minute!
-
Aug 31st, 2000, 04:25 PM
#6
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
-
Aug 31st, 2000, 04:25 PM
#7
_______
<?>
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
-
Aug 31st, 2000, 04:29 PM
#8
Monday Morning Lunatic
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
-
Aug 31st, 2000, 04:29 PM
#9
Lively Member
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.
-
Aug 31st, 2000, 04:31 PM
#10
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.
-
Aug 31st, 2000, 04:33 PM
#11
Lively Member
Megatron - I know it was a typo.
-
Aug 31st, 2000, 04:35 PM
#12
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
-
Aug 31st, 2000, 04:35 PM
#13
_______
<?>
...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
-
Sep 1st, 2000, 02:20 PM
#14
Monday Morning Lunatic
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
-
Sep 1st, 2000, 02:26 PM
#15
_______
<?>
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
-
Sep 1st, 2000, 03:23 PM
#16
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|