Declaration Contexts and Default Access Levels (Visual Basic)
Updated: July 20, 2015
For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.
This topic describes which Visual Basic types can be declared within which other types, and what their access levels default to if not specified.
The declaration context of a programming element is the region of code in which it is declared. This is often another programming element, which is then called the containing element.
The levels for declaration contexts are the following:
Namespace level — within a source file or namespace but not within a class, structure, module, or interface
Module level — within a class, structure, module, or interface but not within a procedure or block
Procedure level — within a procedure or block (such as
The following table shows the default access levels for various declared programming elements, depending on their declaration contexts.
|Declared element||Namespace level||Module level||Procedure level|
|Variable (Dim Statement)||Not allowed|
|Constant (Const Statement)||Not allowed|
|Enumeration (Enum Statement)||Not allowed|
|Class (Class Statement)||Not allowed|
|Structure (Structure Statement)||Not allowed|
|Module (Module Statement)||Not allowed||Not allowed|
|Interface (Interface Statement)||Not allowed|
|Procedure (Function Statement, Sub Statement)||Not allowed||Not allowed|
|External reference (Declare Statement)||Not allowed||Not allowed|
|Operator (Operator Statement)||Not allowed||Not allowed|
|Property (Property Statement)||Not allowed||Not allowed|
|Default property (Default)||Not allowed||Not allowed|
|Event (Event Statement)||Not allowed||Not allowed|
|Delegate (Delegate Statement)||Not allowed|
For more information, see Access Levels in Visual Basic.