|
-
Feb 27th, 2007, 05:45 AM
#1
Thread Starter
New Member
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
-
Feb 27th, 2007, 06:09 AM
#2
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.
-
Feb 27th, 2007, 07:19 AM
#3
Thread Starter
New Member
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.
-
Feb 27th, 2007, 10:26 AM
#4
Re: Lifetime of a public form variable
Correct. The only way to totally "unload" the form is to unload the program itself.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
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
|