473,598 Members | 2,953 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Why do we need Namespace and Module?

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
4 1280
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******** ********@TK2MSF TNGP12.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
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******** ********@TK2MSF TNGP12.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
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******** ********@TK2MSF TNGP12.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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1958
by: Blair Hall | last post by:
Can anyone please tell me how to correctly use a built in function when there is a function of the same name in local scope? Here is an example. Suppose the following is in myApply.py: def apply(func,seq): # # Code can default to # built-in definition in some cases: return __builtins__.apply(func,seq)
10
3079
by: Jeff Wagner | last post by:
I am in the process of learning Python (obsessively so). I've been through a few tutorials and read a Python book that was lent to me. I am now trying to put what I've learned to use by rewriting that Numerology program I wrote years ago in VB. There are times I am totally stuck (for instance, I just had an idea to put the numerical values of the alphabet and months of the year in a dictionary located in a function. Then, I can import the...
8
2064
by: Elaine Jackson | last post by:
I would like to be able to write a function f, which will live in a module M, and will call a function g, such that, when f is imported from M into the interpreter, and invoked there, its invokation of g will return the interpreter's global namespace. Is there a way to do this and, if so, how? Muchas gracias for any and all assistance. Peace
15
3667
by: drdoubt | last post by:
using namespace std In my C++ program, even after applying , I need to use the std namespace with the scope resolution operator, like, std::cout, std::vector. This I found a little bit cumbersome to always include std. I somewhere found a trick to overcome this problem. By using using std::cout;
3
1481
by: seberino | last post by:
At top of a module I have an integer like so... foo = 4 In a function in that module I know I need to do 'global foo' to get at the value 4. .... IIRC, for dictionaries you DO NOT have this issue?
4
1603
by: Ron | last post by:
Hello, I have added a Namespace to my vb.net project. The namespace is the name of the project. Then I start the project from Sub Main Module1 Sub Main() Application.Run(New MyProj.Form1) End Sub
4
2522
by: David A | last post by:
I'm trying to "isolate" some unmanaged calls to DLLs in a separate namespace so I can have all the unmanaged calls to DLL functions in a separate module and then these can be called from any other module using the "Imports" statement. But I can't get it to work, at least not in the manner that I'd prefer. You can call the functions using the fully-qualified name, e.g. "MySpecial.UnmanagedCode.MyFunction". But I want to be able to work in...
9
1756
by: Fuzzyman | last post by:
Hello, I'm trying to redirect standard out in a single namespace. I can replace sys.stdout with a custom object - but that affects all namespaces. There will be code running simultaneously that could import sys afterwards - so I don't want to make the change in the sys module.
8
3481
by: Brett Romero | last post by:
I have this situation: myEXE <needs< DerivedClass <which needs< BaseClass Meaning, myEXE is using a type defined in DerivedClass, which inherits from BaseClass. I include a reference to DerivedClass in myEXE, which gives this error: The type 'BaseAssembly.SomeClass' is defined in an assembly that is not referenced. You must add a reference to assembly 'BaseAssembly,
0
7894
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8262
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6711
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3894
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3938
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1500
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.