468,505 Members | 1,743 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

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 3799
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Anonymous | last post: by
2 posts views Thread by Anonymous | last post: by
1 post views Thread by Rolf Kemper | last post: by
4 posts views Thread by Dan Elliott | last post: by
7 posts views Thread by Kevin Newman | last post: by
22 posts views Thread by dean | last post: by
9 posts views Thread by vthomasset | last post: by
3 posts views Thread by CrazyJohn | last post: by
12 posts views Thread by Taras_96 | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.