How to Control the Scope of a Variable
Usually, a variable is in scope, or has visibility for reference, in all of the section in which you declare it. It is also possible that a variable's access level can have an effect on its scope. See Scope for more information.
Scope at block or procedure level
To give a variable visibility only in a block, put one of the statements Dim
or New
between the first and last lines of that block.
For example, you can put Dim
between the lines For
and End
of a loop of type For
.
You can refer to the variable only in the block.
To give a variable visibility only in a procedure, put one of the statements Dim
or New
in the procedure, but not in a block.
You can refer to the variable only in the procedure, which includes all blocks contained in that procedure.
Scope at module or namespace level
TODO
Example
TODO
Recommended scope
TODO