Module-level Strings 
Author Message
 Module-level Strings

When you unload a form, only the code is unloaded, not variables
To released all variables of a unloaded form, just set the form object to
Nothing

Ex :
Simple project using a module and a form with 2 buttons on it

Module code :

Sub Main
        Form1.Show 1
        Form1.Show 1
        Set Form1 = Nothing
        Form1.Show 1
End Sub

Form1 code :

Dim s As String

Sub Command1_Click()
        s = "Foo"
End Sub

Sub Command2_Click()
        Print "<" & s & ">"
End Sub

Run the project :
The first time the form appears, click on button 1 and on button 2
This will display "<Foo>"
Unload the form by click on the 'x' control button
The second time the form appears, click only on the button 2
This will display "<Foo>"
This show you that even if the form was unloaded, variables were not
unloaded
The third time the form appears, click only on the button 2
This will display "<>"
This show you that variables were unloaded by setting Form1 to Nothing

Best regards,

Luc Vaillant
TF1 Publicite - Micro Media
1, Quai du Point du Jour
92656 Boulogne Billancourt Cedex
France



Quote:
> According to "Optimizing Visual Basic 4.0"(on-line at
> http://www.*-*-*.com/ ) by Drew
> Fletcher at Microsoft, the memory used by module-level string variables
> remains in existence as long as your program is running.

> He states you should make each one equal to "" when closing your form.

> The way I read this, if you do the following in (general declarations):

> Dim s As String

> and in your form, assign

> s = "Foo"

> then, 3 bytes are taken and not returned until you application ends.

> Two questions:

> 1.  Do I understand this correctly?
> 2.  Has anyone been able to actually document this affect using a little
> adhoc project or something?

> Thanks, earl damron :-|



Tue, 13 Jul 1999 03:00:00 GMT  
 Module-level Strings

According to "Optimizing Visual Basic 4.0"(on-line at
http://www.microsoft.com/vbasic/techinfo/optim1.htm or on MSDN) by Drew
Fletcher at Microsoft, the memory used by module-level string variables
remains in existence as long as your program is running.

He states you should make each one equal to "" when closing your form.

The way I read this, if you do the following in (general declarations):

Dim s As String

and in your form, assign

s = "Foo"

then, 3 bytes are taken and not returned until you application ends.

Two questions:

1.  Do I understand this correctly?
2.  Has anyone been able to actually document this affect using a little
adhoc project or something?

Thanks, earl damron :-|



Tue, 13 Jul 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Module-level Strings

2. Module Level Versus Subroutine Level

3. dim at procedure level or module level

4. Works at Module level but not at Form

5. A97: Module-level Variables

6. Publicly declaring Dynamic Arrays at Module Level

7. Please, help Dialog forms and module-level variables

8. module level programming

9. Order Class vs Module-level variables

10. Module-level multiple-record recordset vs temp single-record recordset

11. Referencing forms in module level code

12. Order Class vs Module-level variables

 

 
Powered by phpBB® Forum Software