Lifetime of a public form variable
Hi all!
From what I've read in manuals a variable declared as public in the Declarations section of a form only lives as long as this form is loaded.
However, when I declare a public string variable (say, A) in a form (say, frm), initialise A, do some operations on A and then unload frm, I still can access A from other forms through frm.A which returns the value set at initialisation.
Why is A not removed from the memory when frm is unloaded? I've tried searching the forum but couldn't find the answer.
I use VB6.
Thanks
Re: Lifetime of a public form variable
I would suspect that you that you could possibly do something like:
Code:
Unload Form2
Set Form2 = Nothing
Whilst the variable contents will be destroyed, the reference to the (public) variable remains.
Re: Lifetime of a public form variable
Thanks for the reply.
I seem to have understood the sequence:
The variable A is really removed from the memory when frm unloads, but any further reference to frm.A makes frm load again and execute Form_Load procedure, which sets A to the initial value.
Re: Lifetime of a public form variable
Correct. The only way to totally "unload" the form is to unload the program itself.