Home All Groups Group Topic Archive Search About

Why do we need Namespace and Module?

Author
8 Apr 2005 5:23 PM
Lewis
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

Author
8 Apr 2005 5:33 PM
rawCoder
From MSDN

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vakeymodule.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/default.asp?url=/library/en-us/vblr7/html/vastmnamespace.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

Show quoteHide quote
<Lewis> wrote in message news:eOuQq%23FPFHA.1176@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
>
>
Author
8 Apr 2005 5:57 PM
Mitchell S. Honnert
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

Show quoteHide quote
<Lewis> wrote in message news:eOuQq%23FPFHA.1176@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
>
>
Author
8 Apr 2005 8:32 PM
Jay B. Harlow [MVP - Outlook]
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

Show quoteHide quote
<Lewis> wrote in message news:eOuQq%23FPFHA.1176@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
|
|
Author
9 Apr 2005 7:59 AM
Adam Goossens
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:
Show quoteHide quote
> 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
>
>