Scope and Lifetime
The scope of a variable is the part or parts of the program in which a variable can be accessed by code. It is also known as the visibility of the variable. When we say that a variable is visible in a specific procedure, for example, we say that the code in that procedure can access the variable. We can also say the scope of the variable is that procedure—and mean the same thing. We are going to use both terms in the rest of this book.
Normally the scope of any variable declared with Dim inside a subroutine or function is from the line following its declaration, up to the end of the subroutine or function. These variables are known as local variables. However, the scope is not extended to the code before the declaration (
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access