Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form unload 1

Status
Not open for further replies.

jslmvl

Vendor
Jan 26, 2008
268
GB
It said that
Unload Form2
will remove Form2 from the memory. However, following code shows it is not true:

Private Sub Command1_Click()
Form2.Show
Form2.Text1 = "Form2 shown."
Unload Form2
Form2.Text1 = "Form2 unloaded." 'We can set text in Form2.Text1 although Form2 was unloaded
Form2.Show 'After loading and showing Form2 again, Form2.Text1 will be "Form2 unloaded."
End Sub

Why??
 
Form2 does get unloaded until you call...

Form2.Text1 = "Form2 Unloaded"

Which loads (or reloads) Form2 once again so that is why you see unloaded message when you reshow it. It is the same as doing this...

Load Form2
Form2.Text1.Text = "Test"
Form2.Visible = True

To illistate this further add this sub to your code...

[tt]
Private Sub DebugPrintLoadedForms()
Dim F As Form
Debug.Print ""
For Each F In Forms
Debug.Print F.Name
Next
Debug.Print ""
[/tt]

Now, we will modify your existing program code just a little.

[tt]
Private Sub Command_Click()

Call DebugPrintLoadedForms
Form2.Show
Call DebugPrintLoadedForms

Unload Form2
Call DebugPrintLoadedForms

Form2.Text1 = "Form2 unloaded." 'We can set text in Call DebugPrintLoadedForms

Form2.Show 'After loading and showing Form2 again, Call DebugPrintLoadedForms

End Sub
[/tt]

So, as you can see when you call Form2.Text1.Text you reload form2 by referincing the control contained within the form.

Hope that helps...



Good Luck

 
OK, I know now, thanks a lot for your explanation.
 
>Form2 does get unloaded

To be more accurate the graphical bits of the form get unloaded from memory. Non-graphical bits do not.
 
>To be more accurate the graphical bits of the form get unloaded from memory. Non-graphical bits do not.

To be or not to be more precise... :) AND any information stored or contained by those graphical elements will also be erased. Case in point, the text value of the text box will be erased unless such value is defined in the properties of the text box or in the form load event.

Then if you call them as shown in the example above, the graphical elements will once again be loaded but not shown unless there is a specific call for the form to be shown (Form2.Show) or the setting of the visible property (Form2.Visible = True) is in the forms load event.

However, if you access any public variables declared within the general declarations portion of the form, the graphical elements will not be loaded once again and thus the form will not be listed in the forms collection.


Don't know if I explained that clearly but after a couple of reads would you say that is more exact??? ;-)
 

>if you access any public variables declared within the general declarations portion of the form

Or Constants. Or if you call any user-defined subs, functions, properties (and even events). There's really quite a lot that doesn't get unloaded ... basically all the code ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top