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

Namespace variable

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a

"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.