O'Reilly logo

Visual Basic® .NET by Example by Bob Donald, Gabriel Oancea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 (

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required