Hi all:
i try to exit my program, how can i unload all my forms? i am using a MDI form and few child form, how can we count the number of the child forms i got? i use different name for each form, i can not use forms.count.... any other way?
Printable View
Hi all:
i try to exit my program, how can i unload all my forms? i am using a MDI form and few child form, how can we count the number of the child forms i got? i use different name for each form, i can not use forms.count.... any other way?
To Unload your forms place this code in the Form_Unload event of your MDI Form.
Code:Dim Frm As Form
For Each Frm In Forms
Unload Frm
Set Frm = Nothing
Next Frm
End
'declares are not needed
Code:'unload all forms
For Each Form In Forms
Unload Form
Set Form = Nothing
Next
Do you think the codes that you gave me can work if the froms are having different name? like aform, bform? and do you know what is Me.load? and how can we know wich form is visible if we want to hide it?
and do we need the END and why
Q1: Do you think the codes that you gave me can work if the froms are having different name?
The codes given will unload all forms no matter what the name is.Code:Public Sub UnloadAllForms()
Dim frm As Form
For Each frm In Forms
Unload frm
Set frm = Nothing
Next frm
End
End Sub
Usage
UnloadAllForms
Q2: and do you know what is Me.load?
This will process code that is in the Form_Load event.Code:Load form1
Q3: and how can we know wich form is visible if we want to hide it?
This will print whatever form is visible on the debug window. If it's not visible, it will not print anything.Code:Public Sub VisibleForms()
Dim frm As Form
For Each frm In Forms
If frm.Visible = True Then
Debug.Print frm.Name & ".Visible = " & frm.Visible
Else
End If
Next frm
End Sub
Q4: and do we need the END and why
END - Terminates execution. Never required by itself but may be placed anywhere in a procedure to close files opened with the Open statement and to clear variables.
You don't need END, it is not required, but you may use it if you wish. Just don't use it by itself, as stated above.
Thanks, I appreciate your help
Also, By any chance if you know how can we load all the forms together at the beginning of playing splashform... because i am not sure if we load them together or we load them when we say show at teh first time... also, how can we know the time to load the forms together at the first time , as we need to let the splash form to stay until we finish loading all the child form.. thanks again
Sure they're not needed but it's a good programming habit to declare them because in many languages (such as C++), it will not compile unless you declare your variables.Quote:
Originally posted by HeSaidJoe
'declares are not needed
What do you mean? Are you answering my question?
Megatron:Code:'unload all forms
For Each Form In Forms
Unload Form
Set Form = Nothing
Next
Why would I have to declare anything as form when
I am unloading each form in forms.
I really can't understand why I have to do this
Declare Frm as Form
For Each Frm In Forms
If you use a single form you don't say
Dim frm as frm
Unload frm
You simply say
Unload Form1
or
Unload Me
There is no declare so why should you declare
a var as a form just to unload multilple forms?
HeSaidJoe, thanks for the help that you gave, so if i have lots of MDI child form and some other forms, when i unload, i don't need to declare right....
Also, do you have any clue about the splash form that i asked above?
Thanks again...
Quote:
Originally posted by dragonyian
Also, By any chance if you know how can we load all the forms together at the beginning of playing splashform... because i am not sure if we load them together or we load them when we say show at teh first time... also, how can we know the time to load the forms together at the first time , as we need to let the splash form to stay until we finish loading all the child form.. thanks again
Code:Private Sub Form_Load() 'splash screen
Load form1
Load form2
Load form3
DoEvents 'load all forms
'after all are loaded...show them all
Form1.Show
Form2.Show
Form3.Show
'etc.
'etc.
End Sub
Maybe i should make myself clear... or maybe i should have explained this clearer....
I have a MDI form with 10 child forms and 2 independent forms and
when i started the project, i have a form called splash form,(project property) what it does just like its name... show a picture... i never use form load in my whole program.. i just "show" them, i am not sure if it is the correct way to do that... if i need to load them, where should i put the load code, load form1, load form2..... if i do like you said put them under splash form, then will the program goes faster than only "show-used" program? how can we know how long to load all the forms together... because i need to show the picture on the splash form also, if it goes too fast.. maybe the user might not be able to see the picture at all.... but it is how others do, i know... so, what would be your suggestion
thanks
I could be wrong on this but I do belive all forms are loaded when your application is loaded and the only form to show it the form declared as your startup form.
You can use VbShow and VbHide to show and not show your forms as long as you don't unload any within the running of your app. They should all be unloaded and set to nothing when you unload your application.
If you have 10 to 15 forms they should load quickly and I would assume that if you let your splash screen show for 4 to 8 seconds you should have no problems.
Code:
frmSplash.hide
form1.show
form2.show
form3.show
form4.show
Whatever...
example: if you have 4 forms and you want only #2 shown
form1.hide
form3.hide
form4.hide
form2.show
Correct me if i am wrong,because i am new to programming
if all the child forms are loaded automatic, why we still need the load function/event?
Say, you used this on a secondary form to free up memory like:
and later you want to show it again, you would use:Code:unload uselessform
HeSaidJoe: Yes, all forms ARE loaded at startup so if you call the form.show method, it never returns an error.Code:load uselessform
Load is the same as:
<except it can't be used to create new instances or forms.> new instance of form = new formCode:Dim Form1 As New Form1
get it?:)
:p
So, in that case, how can we load those we need when we need it.. because as you said... it will load everything when we run the program... what would be the best hit, tip to handle load/unload MDI child form....
AndCode:Unload MDIForm.ActiveForm
Also, I'll give you the code for Unloading ANY form soon.Code:Set ff as New Form1
ff.Show