With a library as big as the one .Net has it is highly likely that two objects would have the same name. The compiler would not know which one you were talking about. .Net uses namespaces to help uniquely identify classes. A class belongs to a namespace this is placed before the class name to clarify the situation. It is rather like using a COM ProgID in VB6.
In order to prevent you having to type in namespaces all the time you can use an
Imports statement at the top of your code file. This following syntax:
Imports [
<aliasname> = ]
<namespace>
To save you even more time VB automatically imports a number of namespaces into all your code files. A list of these can be found in the project settings.
When writing your own classes you might want to put your code in your own namespaces. This can be done using the
namespace keyword:
Namespace
<name>
<class definitions>
end namespace
This is a good idea as it helps prevent your names conflicting with other developers’ classes, however it can be a bit tedious. VB.Net comes to the rescue again by allowing you to set a default namespace for all the classes in your project. This is set in project properties and is defaulted to the same name as the project. Hence why
MsgBox is a namespace.
The full name of the
MsgBox function is
Microsoft.VisualBasic.Information.MsgBox but you can omit the
Microsoft.VisualBasic assuming you don’t have another namespace called
Information. If you use this instead of just
MsgBox it should sort out the problem, or you could change the namespace for your project.
Caffein
![[afro] [afro] [afro]](/data/assets/smilies/afro.gif)