Imports namespace names from referenced projects and assemblies. Also imports namespace names defined within the same project as the file in which the statement appears.
Imports [ aliasname = ] namespace [ . element ]
Each file can contain any number of Imports statements. Imports statements must be placed before any declarations, including Module or Class statements, and before any references to identifiers.
The scope of the elements made available by an Imports statement depends on how specific you are when using the Imports statement. For example, if only a namespace is specified, all uniquely named members of that namespace, and members of modules within that namespace, are available without qualification. If both a namespace and the name of an element of that namespace are specified, only the members of that element are available without qualification.
It is not permitted to define a member at module level with the same name as an import alias.
The following example imports the Microsoft.VisualBasic.Strings class and assigns an alias, Str
, that can be used to access the Left method.
Imports
Str = Microsoft.VisualBasic.Strings
' Place Imports statements at the top of your program
Class MyClass1
Sub ShowHello()
MsgBox(Str.Left("Hello World", 5)) ' Displays the word "Hello"
End Sub
End Class