The scope of a declared element is the set of all code that can refer to it without qualifying its name or making it available through an Imports statement. An element can have scope at one of the following levels:
- Block scope — available only within the code block in which it is declared
- Procedure scope — available only within the procedure in which it is declared
- Module scope — available to all code within the module, class, or structure in which it is declared
- Namespace scope — available to all code in the namespace
These levels of scope progress from the narrowest (block) to the widest (namespace), where narrowest scope means the smallest set of code that can refer to the element without qualification.
You specify the scope of an element when you declare it. The scope can depend on the following factors:
- The region (block, procedure, module, class, or structure) in which you declare the element
- The namespace containing the element's declaration
- The accessibility you declare for the element
Use care when you define variables with the same name but different scope, because doing so can lead to unexpected results. For more information, see Reference Matching.