|
-
Mar 31st, 2000, 01:18 AM
#1
Thread Starter
Junior Member
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
-
Mar 31st, 2000, 02:11 AM
#2
transcendental analytic
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
-
Mar 31st, 2000, 02:24 AM
#3
Lively Member
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.
-
Mar 31st, 2000, 02:56 AM
#4
Thread Starter
Junior Member
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
-
Mar 31st, 2000, 03:41 AM
#5
New Member
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
-
Mar 31st, 2000, 04:26 AM
#6
Thread Starter
Junior Member
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
-
Mar 31st, 2000, 04:49 AM
#7
Junior Member
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
-
Mar 31st, 2000, 05:04 AM
#8
Thread Starter
Junior Member
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?
-
Mar 31st, 2000, 05:14 AM
#9
The best way to achieve this is to use Forms collection.
Code:
Dim frm As Form
For Each frm In Forms
Unload frm
Next
-
Mar 31st, 2000, 05:21 AM
#10
Lively Member
wow
Wow! I can't believe that it took 8 postings to get a descent answer for that question. Nice job serge! 
-
Mar 31st, 2000, 05:35 AM
#11
transcendental analytic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|