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 (

Get Visual Basic® .NET by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.