473,396 Members | 2,013 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Namespace variable

Little confused...

When I declare a namespace variable in module I can use it anywhere in the
project. That's clear.

I read a book in which the author said that namespace variables can be
declared in a class outside of any subs or functions... below " Windows Form
Designer generated code " with the Public keyword and I could use this
variable in the whole project's namespace.

I discovered that it can be used but I have to instantiate that class which
before I can use that variable in let say some other form in that same
project. I thought I could use it without the need to instantiate that
class.
Nov 21 '05 #1
3 4009
"dotNETnews" <do********@gmail.com> schrieb:
When I declare a namespace variable in module I can use it anywhere in the
project. That's clear.

I read a book in which the author said that namespace variables can be
declared in a class outside of any subs or functions... below " Windows
Form Designer generated code " with the Public keyword and I could use
this variable in the whole project's namespace.


What's a "namespace variable"? I have never heard this term. Can you post
a code sample that demonstrates what you want to archieve?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2
Use the shared keyword in a class.

Public Class Class1
Public Shared MyVar As Integer
End Class

You can use it like Class1.MyVar without instaniating it.

A Module is just a VB specific construct. It is basically a shared class.
One unique thing about a Module is that you can reference the public
variables/methods without prefixing with the Module name.

I don't believe "namespace variable" is correct terminology. At least, I've
never heard of it before.

Greg

"dotNETnews" <do********@gmail.com> wrote in message
news:ON****************@tk2msftngp13.phx.gbl...
Little confused...

When I declare a namespace variable in module I can use it anywhere in the
project. That's clear.

I read a book in which the author said that namespace variables can be
declared in a class outside of any subs or functions... below " Windows
Form Designer generated code " with the Public keyword and I could use
this variable in the whole project's namespace.

I discovered that it can be used but I have to instantiate that class
which before I can use that variable in let say some other form in that
same project. I thought I could use it without the need to instantiate
that class.

Nov 21 '05 #3

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:OU**************@TK2MSFTNGP09.phx.gbl...
Use the shared keyword in a class.

Public Class Class1
Public Shared MyVar As Integer
End Class

You can use it like Class1.MyVar without instaniating it.

A Module is just a VB specific construct. It is basically a shared class.
One unique thing about a Module is that you can reference the public
variables/methods without prefixing with the Module name.

I don't believe "namespace variable" is correct terminology. At least,
I've never heard of it before.

Greg

"dotNETnews" <do********@gmail.com> wrote in message
news:ON****************@tk2msftngp13.phx.gbl...
Little confused...

When I declare a namespace variable in module I can use it anywhere in
the project. That's clear.

I read a book in which the author said that namespace variables can be
declared in a class outside of any subs or functions... below " Windows
Form Designer generated code " with the Public keyword and I could use
this variable in the whole project's namespace.

I discovered that it can be used but I have to instantiate that class
which before I can use that variable in let say some other form in that
same project. I thought I could use it without the need to instantiate
that class.


It from Murach's book, Beginning Visual Basic.NET. They call variables with
namespace scope - namespace variables.
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Anonymous | last post by:
Is namespace the same thing as scope? While reading the book "Thinking in C++", I was under the impression that namespace is, well, a namespace--a feature to create a hiearchy for identifiers...
2
by: Anonymous | last post by:
How do I reference a namespace variable in a multi-file project? Do I use the keyword 'extern'? If so, does the word 'extern' modify the namespace or the individual variables within the...
1
by: Rolf Kemper | last post by:
Dear Experts, I'm going to create an Excell spreadsheet xml. So far things work very well. But in case I add <Row> elements by a recursive template call it goes wrong. See the attached XSLT...
4
by: Dan Elliott | last post by:
Hello, Converting from a working C program to C++, I run into the following error: I have a header: (header.h) namespace shared{ ... struct X{ ...
7
by: Kevin Newman | last post by:
I've been toying with a namespace manager, and wanted to get some input. So what do you think? if (typeof com == 'undefined') var com = {}; if (!com.unFocus) com.unFocus = {}; ...
22
by: dean | last post by:
Hi all, We have a few existing classes that we want to put into either another class or a namespace, so that we can avoid naming conflicts. As far as I can see the syntax is identical from a...
9
by: vthomasset | last post by:
Hi, Sorry for the bad subject, but i couldn't figure a better one. I would like to understand why a variable declared non static in a header causes multiple symbol definitions (if included in...
3
by: CrazyJohn | last post by:
Hi guys, This is my first time posting question here, if I break any rules, please kindly point out. And I'm really glad to be a part of this community. Here is my question, Our lecturer...
12
by: Taras_96 | last post by:
Hi everyone, AFAIK external linkage allows you to refer to variables/functions outside of the current translation unit. A variable in an unnamed namespace is similar to declaring a static...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...
0
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,...

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.