Static and Dim outside procedure

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Could someone please tell me what's the different between Static statement
and Dim variables with Public and at module level?
Because I find that both way retain value.

Thanks
Regards
Augustus
 
augustus,
<From Help, Search="Static">
Static Statement

Used at procedure level to declare variables and allocate storage space.
Variables declared with the Static statement retain their values as long as
the code is running.
Syntax
Static varname[([subscripts])] [As [New] type] [, varname[([subscripts])]
[As [New] type]] . .

</From Help>

<From Help, Search="Scope">
Understanding Scope and Visibility

Scope refers to the availability of a variable, constant, or procedure for
use by another procedure. There are three scoping levels: procedure-level,
private module-level, and public module-level.
You determine the scope of a variable when you declare it. It's a good idea
to declare all variables explicitly to avoid naming-conflict errors between
variables with different scopes.

</From Help>

NickHK
 
Hi

If variable declared with Public and at the Declarations section of module
could have the same effect as Static within a procedure, ie the variable
retain their values as long as the code running, then what’s the point of
having Static?

Thanks
Regards
Augustus

NickHK said:
augustus,
<From Help, Search="Static">
Static Statement

Used at procedure level to declare variables and allocate storage space.
Variables declared with the Static statement retain their values as long as
the code is running.
Syntax
Static varname[([subscripts])] [As [New] type] [, varname[([subscripts])]
[As [New] type]] . .

</From Help>

<From Help, Search="Scope">
Understanding Scope and Visibility

Scope refers to the availability of a variable, constant, or procedure for
use by another procedure. There are three scoping levels: procedure-level,
private module-level, and public module-level.
You determine the scope of a variable when you declare it. It's a good idea
to declare all variables explicitly to avoid naming-conflict errors between
variables with different scopes.

</From Help>

NickHK

augustus said:
Hi,

Could someone please tell me what's the different between Static statement
and Dim variables with Public and at module level?
Because I find that both way retain value.

Thanks
Regards
Augustus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top