473,386 Members | 1,819 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,386 software developers and data experts.

proper place for a variable

Hello,
I need one specific value in all the applicationspecific forms and classes
of my application. What is the proper place to put it? At the moment I use a
module with a public constant and that seems to be a handy place. Passing it
as a parameter doesn't seem to be very efficient. What do you suggest?
Thanks
Frank
Nov 20 '05 #1
11 1338

"Frank" <fr***@frank.com> wrote in message
news:cc**********@news3.tilbu1.nb.home.nl...
Hello,
I need one specific value in all the applicationspecific forms and classes
of my application. What is the proper place to put it? At the moment I use a module with a public constant and that seems to be a handy place. Passing it as a parameter doesn't seem to be very efficient. What do you suggest?
Thanks
Frank

I'm sure others will have contrasting opinions, but here goes...
Even though allowing global variables is a decidedly non-OO feature brought
forward from previous VB versions, I would be very tempted to do exactly as
you are now doing. I would not agree if it were a variable instead of a
named constant, but I see no harm in a global named constant.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 20 '05 #2
Remember, a module is a 'Sealed' Class which in imported automatically, all
members and properties are 'Shared'.

Personally, I avoid Modules and perfer to explicitly use Classes, this
avoids all the confusion surrounding Modules.

HTH

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Peter van der Goes" <p_**********@toadstool.u> wrote in message
news:Oi*************@TK2MSFTNGP11.phx.gbl...

"Frank" <fr***@frank.com> wrote in message
news:cc**********@news3.tilbu1.nb.home.nl...
Hello,
I need one specific value in all the applicationspecific forms and classes of my application. What is the proper place to put it? At the moment I
use a
module with a public constant and that seems to be a handy place.
Passing it
as a parameter doesn't seem to be very efficient. What do you suggest?
Thanks
Frank

I'm sure others will have contrasting opinions, but here goes...
Even though allowing global variables is a decidedly non-OO feature

brought forward from previous VB versions, I would be very tempted to do exactly as you are now doing. I would not agree if it were a variable instead of a
named constant, but I see no harm in a global named constant.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Nov 20 '05 #3
You should declare your public constants in a class, lets GLOBALS

Public Class GLOBALS

Public Const PI As Double = 3.142

End Class
Dim a As Double = GLOBALS.PI

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Frank" <fr***@frank.com> wrote in message
news:cc**********@news3.tilbu1.nb.home.nl...
Hello,
I need one specific value in all the applicationspecific forms and classes
of my application. What is the proper place to put it? At the moment I use a module with a public constant and that seems to be a handy place. Passing it as a parameter doesn't seem to be very efficient. What do you suggest?
Thanks
Frank

Nov 20 '05 #4
* "Frank" <fr***@frank.com> scripsit:
I need one specific value in all the applicationspecific forms and classes
of my application. What is the proper place to put it? At the moment I use a
module with a public constant and that seems to be a handy place. Passing it
as a parameter doesn't seem to be very efficient. What do you suggest?


I suggest a friend module that provides the variables and constants.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:
Remember, a module is a 'Sealed' Class which in imported automatically, all
members and properties are 'Shared'.

Personally, I avoid Modules and perfer to explicitly use Classes, this
avoids all the confusion surrounding Modules.


What confusions?!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6
I didnt say you were confused, however, a lot of people seem to be.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uS*************@TK2MSFTNGP12.phx.gbl...
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:
Remember, a module is a 'Sealed' Class which in imported automatically, all members and properties are 'Shared'.

Personally, I avoid Modules and perfer to explicitly use Classes, this
avoids all the confusion surrounding Modules.


What confusions?!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 20 '05 #7
Hi Frank,

I prefer a class with shared members.

And before the others say it, that is the same as a module, however I never
use a module.

Cor
Nov 20 '05 #8
Ok, a class with globals it is.
Thanks for your opinions.
Fra
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OU**************@TK2MSFTNGP12.phx.gbl...
Hi Frank,

I prefer a class with shared members.

And before the others say it, that is the same as a module, however I never use a module.

Cor

Nov 20 '05 #9

I encounter this problem quite a lot, and usually use a class with
shared members as shown above. Something as simple such as

Class myData

public shared strSetting as string = ""
public shared intWhatever as integer = 0

End Class

then just access your data via myData.*

Although shared values arent really true OO either, they are much closer
than modules IMO, and I tend to stay away from modules as much as possible.


Cor Ligthert wrote:
Hi Frank,

I prefer a class with shared members.

And before the others say it, that is the same as a module, however I never
use a module.

Cor

Nov 20 '05 #10
There are a number of issues here:

1. There really isn't a good OO place to put what we used to call "header
files". From what I can tell the community has pretty much decided that
putting them in shared properties or fields of a class. This seems to work
fine and from what I can see has no ill effects.

2. In general the VB.NET community is familiar with modules which as I
understand it are converted to classes with all of the members shared when
the IL is created. And, since modules are a "standard" part of VB I don't
see any reason they shouldn't be used.

IMHO putting "global" constants in either a module, or as shared members of
a class is quite acceptable. For those solutions where there are multiple
projects and these constants need to be made available to all projects, a
separate project containing either a module or class with shared members is
acceptable. Either technique should be easily understandable by other
developers.

-Sam Matzen
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:OR***************@TK2MSFTNGP10.phx.gbl...
I didnt say you were confused, however, a lot of people seem to be.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uS*************@TK2MSFTNGP12.phx.gbl...
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:
Remember, a module is a 'Sealed' Class which in imported
automatically,
all members and properties are 'Shared'.

Personally, I avoid Modules and perfer to explicitly use Classes, this
avoids all the confusion surrounding Modules.


What confusions?!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


Nov 20 '05 #11
Thanks, but your stating whats already been said with the exception of
contradicting what I said about Modules being confusing for some people.

You will see this question come up with regularity for people who have come
from VB6 to .NET, they want to do things in the old way and are familiar
with Modules, but dont realise that they dont work the same way.

I can say this with some authority having been on this NG for nearly a year
now.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Samuel L Matzen" <sm*****@slm.com> wrote in message
news:O%****************@TK2MSFTNGP12.phx.gbl...
There are a number of issues here:

1. There really isn't a good OO place to put what we used to call "header
files". From what I can tell the community has pretty much decided that
putting them in shared properties or fields of a class. This seems to work fine and from what I can see has no ill effects.

2. In general the VB.NET community is familiar with modules which as I
understand it are converted to classes with all of the members shared when
the IL is created. And, since modules are a "standard" part of VB I don't
see any reason they shouldn't be used.

IMHO putting "global" constants in either a module, or as shared members of a class is quite acceptable. For those solutions where there are multiple
projects and these constants need to be made available to all projects, a
separate project containing either a module or class with shared members is acceptable. Either technique should be easily understandable by other
developers.

-Sam Matzen
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:OR***************@TK2MSFTNGP10.phx.gbl...
I didnt say you were confused, however, a lot of people seem to be.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uS*************@TK2MSFTNGP12.phx.gbl...
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit: > Remember, a module is a 'Sealed' Class which in imported

automatically,
all
> members and properties are 'Shared'.
>
> Personally, I avoid Modules and perfer to explicitly use Classes, this > avoids all the confusion surrounding Modules.

What confusions?!

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>



Nov 20 '05 #12

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

Similar topics

4
by: TK | last post by:
I'm sure this is probably the wrong place to ask, but is there a way to execute an SSI script in javascript? I'm using an SSI script to read a memory address, and I'd like to be able to update...
1
by: seberino | last post by:
Python lets me access module level variables from *anywhere*. All I have to do is add module name in front. e.g. mymodule.myvariable Is this considered a 'global'? Or, does a 'global...
6
by: Nawab | last post by:
Hey can anyone explain to me the difference between Mid and Mid$ ....i notice sometimes when i a running the update query with Mid$ it tells me that for example 3 records will be updated ( which in...
1
by: RC | last post by:
I have an Access 2002 database with many tables and forms (but just to keep things simple, let's say the DB has one Table "Table1" and one Form "Form1"). I have managed to cobble together so much...
1
by: Frank | last post by:
Hello, I need one specific value in all the applicationspecific forms and classes of my application. What is the proper place to put it? At the moment I use a module with a public constant and...
3
by: Brent Ritchie | last post by:
Hello all, I just got my first job in the IT field as a junior programmer. Right now I am working on my first assignment. It's not the best assignment in the world, but it's something I have...
2
by: craigkenisston | last post by:
Im trying to make an application using all the out of the box stuff for data displaying. Using (or trying to) use a BLL and DLL. Now, in my database, the tables and columns have names like these: ...
11
by: giddy | last post by:
hi , ok , i have a programming background but i'm new to C# . i'm also self taught so : i have a datagridview that should act differently depending on which user has signed in now is it...
171
by: Raman | last post by:
Hi All, Here is a small Code, int main(void) { char *p=(char *) malloc(100); strcpy(p,"Test1234567890"); p=p+10; free(p);
13
by: Chris Thomasson | last post by:
Here is some info on a C++ allocator prototype I am working on: http://groups.google.com/group/comp.lang.c++/browse_frm/thread/beeee1f61fdbb52c Any tried-and-true techniques for calculating the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.