References and the Imports Statement (Visual Basic)
Updated: July 20, 2015
For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.
You can make external objects available to your project by choosing the Add Reference command on the Project menu. References in Visual Basic can point to assemblies, which are like type libraries but contain more information.
Assemblies include one or more namespaces. When you add a reference to an assembly, you can also add an
Imports statement to a module that controls the visibility of that assembly's namespaces within the module. The
Imports statement provides a scoping context that lets you use only the portion of the namespace necessary to supply a unique reference.
Imports statement has the following syntax:
Aliasname refers to a short name you can use within code to refer to an imported namespace.
Namespace is a namespace available through either a project reference, through a definition within the project, or through a previous
A module may contain any number of
Imports statements. They must appear after any
Option statements, if present, but before any other code.
Do not confuse project references with the
Imports statement makes it easier to access methods of classes by eliminating the need to explicitly type the fully qualified names of references. Aliases let you assign a friendlier name to just one part of a namespace. For example, the carriage return/line feed sequence that causes a single piece of text to be displayed on multiple lines is part of the ControlChars module in the Microsoft.VisualBasic namespace. To use this constant in a program without an alias, you would need to type the following code:
Imports statements must always be the first lines immediately following any
Option statements in a module. The following code fragment shows how to import and assign an alias to the Microsoft.VisualBasic.ControlChars module:
Future references to this namespace can be considerably shorter:
Imports statement does not include an alias name, elements defined within the imported namespace can be used in the module without qualification. If the alias name is specified, it must be used as a qualifier for names contained within that namespace.
NIB How to: Add or Remove References By Using the Add Reference Dialog Box
Namespaces in Visual Basic
Assemblies and the Global Assembly Cache
How to: Create and Use Assemblies Using the Command Line
Imports Statement (.NET Namespace and Type)