ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Static and Dim outside procedure (https://www.excelbanter.com/excel-programming/324371-static-dim-outside-procedure.html)

augustus

Static and Dim outside procedure
 
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

NickHK

Static and Dim outside procedure
 
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" wrote in message
...
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

Static and Dim outside procedure
 
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 whats the point of
having Static?

Thanks
Regards
Augustus

"NickHK" wrote:

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" wrote in message
...
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






All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com