By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,474 Members | 3,139 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,474 IT Pros & Developers. It's quick & easy.

Why do we need Namespace and Module?

P: n/a
When I add a new module in the project explorer pane, the wizard
inserts a Module1 scope, so any variables I will put there can be
accessed with a qulification, e.g.
dim a as integer
will be accessed elsewhere as Module1.a
In what way is the Namespace keyword different from the Module keyword?
i.e. I can also use
Namespace Module1 instaed of
Module Module1
and the access elsewhere will still be
Module1.a
tia
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
From MSDN

http://msdn.microsoft.com/library/de...akeymodule.asp
Modules are a reference type similar to classes, but with some important
distinctions. The members of a module are implicitly Shared and scoped to
the declaration space of the standard module's containing namespace, rather
than just to the module itself. Unlike classes, modules can never be
instantiated, do not support inheritance, and cannot implement interfaces. A
module can only be declared in a namespace and cannot be nested in another
type.

while

http://msdn.microsoft.com/library/de...mnamespace.asp
Namespaces are used as an organizational system - a way of presenting
program components that are exposed to other programs and applications.
Namespaces are always Public; therefore the declaration of a namespace
cannot include access modifiers. However, the components within the
namespace may have Public or Friend access. If it is not stated, the default
access type is Friend.

HTH
rawCoder

<Lewis> wrote in message news:eO****************@TK2MSFTNGP12.phx.gbl...
When I add a new module in the project explorer pane, the wizard
inserts a Module1 scope, so any variables I will put there can be
accessed with a qulification, e.g.
dim a as integer
will be accessed elsewhere as Module1.a
In what way is the Namespace keyword different from the Module keyword?
i.e. I can also use
Namespace Module1 instaed of
Module Module1
and the access elsewhere will still be
Module1.a
tia

Nov 21 '05 #2

P: n/a
In addition to what rawCoder posted, I would add this...

Module and class names are physical ways of grouping different methods,
whereas Namespaces give you the option to group modules and classes into
virtual groups. For example, two classes may be in two completely different
inheritence hierarchies, but because they have a similar functionality, they
could be in the same Namespace. In my mind, "class/module" is physical and
"Namespace" is logical. Does that make sense?

- Mitchell S. Honnert

<Lewis> wrote in message news:eO****************@TK2MSFTNGP12.phx.gbl...
When I add a new module in the project explorer pane, the wizard
inserts a Module1 scope, so any variables I will put there can be
accessed with a qulification, e.g.
dim a as integer
will be accessed elsewhere as Module1.a
In what way is the Namespace keyword different from the Module keyword?
i.e. I can also use
Namespace Module1 instaed of
Module Module1
and the access elsewhere will still be
Module1.a
tia

Nov 21 '05 #3

P: n/a
Lewis,
In addition to the other comments.

A Module introduces a new Type into your program. A Type (Class, Module,
Enum, Delegate, Interface) can contain Subs, Functions, Properties, Events,
Fields and other Types (based on the type of Type that it is).

A Namespaces is used to organize Types & other Namespaces.

Hope this helps
Jay

<Lewis> wrote in message news:eO****************@TK2MSFTNGP12.phx.gbl...
| When I add a new module in the project explorer pane, the wizard
| inserts a Module1 scope, so any variables I will put there can be
| accessed with a qulification, e.g.
| dim a as integer
| will be accessed elsewhere as Module1.a
| In what way is the Namespace keyword different from the Module keyword?
| i.e. I can also use
| Namespace Module1 instaed of
| Module Module1
| and the access elsewhere will still be
| Module1.a
| tia
|
|
Nov 21 '05 #4

P: n/a
Quick clarification:

If you define a module like this:

---
Public Module Foo
Dim Bar As Integer
End Module
---

You cannot access Bar from anywhere but inside the module. The reason is
that Bar in this case has Private scope - only other members of the same
module can access it.

You would have to define Bar like to be able to access it anywhere:

---
Public Module Foo
Public Bar As Integer
End Module
---

Now you can refer to "Bar" anywhere you like - and you don't have to
qualify it with the name of the module. That's one of the "advantages"
(although some people disagree. I am one of these people) of Modules -
it's a throwback to the old VB behaviour.

Maybe this explanation will help: Modules group related functions into a
self-contained block of functionality. Namespaces then group those
blocks of functionality even further, so that's why you put modules
which have similar functionality into the same namespace. This way you
can organise all of your modules, and pick-and-choose which ones you
need (just by importing the right Namespace).

If that makes any sense :)

Regards,
-Adam.

Lewis wrote:
When I add a new module in the project explorer pane, the wizard
inserts a Module1 scope, so any variables I will put there can be
accessed with a qulification, e.g.
dim a as integer
will be accessed elsewhere as Module1.a
In what way is the Namespace keyword different from the Module keyword?
i.e. I can also use
Namespace Module1 instaed of
Module Module1
and the access elsewhere will still be
Module1.a
tia

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.