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

Globally accessible variables and functions?

I'm writing a VB.NET application, and I have a lot of general-purpose
utility functions that need to be available throughout the program
(like functions that perform standard date conversions peculiar to my
app, etc.) and some global data values (i.e. the start and end dates
of a billing period).

I have gathered them all into an object and would like to make that
object a global variable - instantiate it once and then be able to
reference it from anywhere in the code that I need to. I don't want
to pay the overhead of recreating the object every time I need it.

Can somebody suggest the best way to accomplish this? I don't see an
equivalent to a global variable in a .BAS module as in VB 6. Is there
a better way to do this in .NET?
Thanks in advance...

Nov 20 '05 #1
8 1988
Hi Douglas,

I do not understand what you mean, with pay for that overhead, recreating
gives the posibility to free resources.

However what you ask is called in VB.net a Shared class, you make that by
setting all the methods and properties shared.

http://msdn.microsoft.com/library/de...redmembers.asp
I hope this helps?

Cor
Nov 20 '05 #2
Hi Douglas,

I do not understand what you mean, with pay for that overhead, recreating
gives the posibility to free resources.

However what you ask is called in VB.net a Shared class, you make that by
setting all the methods and properties shared.

http://msdn.microsoft.com/library/de...redmembers.asp
I hope this helps?

Cor
Nov 20 '05 #3
On Thu, 8 Apr 2004 19:33:48 +0200, "Cor Ligthert"
<no**********@planet.nl> wrote:
Hi Douglas,

I do not understand what you mean, with pay for that overhead, recreating
gives the posibility to free resources.
I fill in some values of a few data members in the new() function - so
there's that overhead, performance-wise.


However what you ask is called in VB.net a Shared class, you make that by
setting all the methods and properties shared.

But that doesn't create the member variables and initialize them, etc.

I think I found the answer in making a "singleton" class - the class
contains an instance of itself, and I use a function I'll call
"Create", which will do:
Public Shared Function Create() As clsMyApplication
If oApp Is Nothing Then
oApp = New clsMyApplication
End If

Return oMyApp
End Function
And then, wherever I need this object, I just "create" it:

dim oMyApp As clsMyApplication = oMyApp.Create()

Which will create the object if necessary, but otherwise will use the
one that is already created. It seems to work well.

http://msdn.microsoft.com/library/de...redmembers.asp
I hope this helps?

Cor


Nov 20 '05 #4
On Thu, 8 Apr 2004 19:33:48 +0200, "Cor Ligthert"
<no**********@planet.nl> wrote:
Hi Douglas,

I do not understand what you mean, with pay for that overhead, recreating
gives the posibility to free resources.
I fill in some values of a few data members in the new() function - so
there's that overhead, performance-wise.


However what you ask is called in VB.net a Shared class, you make that by
setting all the methods and properties shared.

But that doesn't create the member variables and initialize them, etc.

I think I found the answer in making a "singleton" class - the class
contains an instance of itself, and I use a function I'll call
"Create", which will do:
Public Shared Function Create() As clsMyApplication
If oApp Is Nothing Then
oApp = New clsMyApplication
End If

Return oMyApp
End Function
And then, wherever I need this object, I just "create" it:

dim oMyApp As clsMyApplication = oMyApp.Create()

Which will create the object if necessary, but otherwise will use the
one that is already created. It seems to work well.

http://msdn.microsoft.com/library/de...redmembers.asp
I hope this helps?

Cor


Nov 20 '05 #5
So then what's the difference between a singleton class, and a class with
all shared members? I mean as far as the end result of what you are trying
to accomplish.

"Dougal Fair" <do****@dougalfair.com> wrote in message
news:40****************@news.goldengate.net...
On Thu, 8 Apr 2004 19:33:48 +0200, "Cor Ligthert"
<no**********@planet.nl> wrote:
Hi Douglas,

I do not understand what you mean, with pay for that overhead, recreating
gives the posibility to free resources.


I fill in some values of a few data members in the new() function - so
there's that overhead, performance-wise.


However what you ask is called in VB.net a Shared class, you make that by
setting all the methods and properties shared.

But that doesn't create the member variables and initialize them, etc.

I think I found the answer in making a "singleton" class - the class
contains an instance of itself, and I use a function I'll call
"Create", which will do:
Public Shared Function Create() As clsMyApplication
If oApp Is Nothing Then
oApp = New clsMyApplication
End If

Return oMyApp
End Function
And then, wherever I need this object, I just "create" it:

dim oMyApp As clsMyApplication = oMyApp.Create()

Which will create the object if necessary, but otherwise will use the
one that is already created. It seems to work well.


http://msdn.microsoft.com/library/de...-us/vbcn7/html

/vaconsharedmembers.asp


I hope this helps?

Cor

Nov 20 '05 #6
So then what's the difference between a singleton class, and a class with
all shared members? I mean as far as the end result of what you are trying
to accomplish.

"Dougal Fair" <do****@dougalfair.com> wrote in message
news:40****************@news.goldengate.net...
On Thu, 8 Apr 2004 19:33:48 +0200, "Cor Ligthert"
<no**********@planet.nl> wrote:
Hi Douglas,

I do not understand what you mean, with pay for that overhead, recreating
gives the posibility to free resources.


I fill in some values of a few data members in the new() function - so
there's that overhead, performance-wise.


However what you ask is called in VB.net a Shared class, you make that by
setting all the methods and properties shared.

But that doesn't create the member variables and initialize them, etc.

I think I found the answer in making a "singleton" class - the class
contains an instance of itself, and I use a function I'll call
"Create", which will do:
Public Shared Function Create() As clsMyApplication
If oApp Is Nothing Then
oApp = New clsMyApplication
End If

Return oMyApp
End Function
And then, wherever I need this object, I just "create" it:

dim oMyApp As clsMyApplication = oMyApp.Create()

Which will create the object if necessary, but otherwise will use the
one that is already created. It seems to work well.


http://msdn.microsoft.com/library/de...-us/vbcn7/html

/vaconsharedmembers.asp


I hope this helps?

Cor

Nov 20 '05 #7
"Dougal Fair" <do****@dougalfair.com> schrieb
I'm writing a VB.NET application, and I have a lot of
general-purpose utility functions that need to be available
throughout the program (like functions that perform standard date
conversions peculiar to my app, etc.) and some global data values
(i.e. the start and end dates of a billing period).

I have gathered them all into an object and would like to make
that object a global variable - instantiate it once and then be able
to reference it from anywhere in the code that I need to. I don't
want to pay the overhead of recreating the object every time I need
it.

Can somebody suggest the best way to accomplish this? I don't see
an equivalent to a global variable in a .BAS module as in VB 6. Is
there a better way to do this in .NET?


Declare them Shared in a Class.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #8
"Dougal Fair" <do****@dougalfair.com> schrieb
I'm writing a VB.NET application, and I have a lot of
general-purpose utility functions that need to be available
throughout the program (like functions that perform standard date
conversions peculiar to my app, etc.) and some global data values
(i.e. the start and end dates of a billing period).

I have gathered them all into an object and would like to make
that object a global variable - instantiate it once and then be able
to reference it from anywhere in the code that I need to. I don't
want to pay the overhead of recreating the object every time I need
it.

Can somebody suggest the best way to accomplish this? I don't see
an equivalent to a global variable in a .BAS module as in VB 6. Is
there a better way to do this in .NET?


Declare them Shared in a Class.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #9

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

Similar topics

15
by: Bob | last post by:
I've tried everything; and I can't seem to get past this VERY (seemingly) simply problem. I want to work with an array variable within a function(s). I can't get it to work; if I: 1) global...
21
by: steve | last post by:
Dont’ make my mistake. It is costly. Say you have defined a variable $var in your main script. Now in a function you access it using: global $var; But you want to set it to null inside the...
13
by: Jean-François Doyon | last post by:
Hello, I'm using MetaClasses to create classes. How do I make these new classes "globally" available? I probably just have to assign them to something magic, but I can't seem to figure out...
4
by: Daniel | last post by:
Hullo =) Inspired by another guy's questions here I've created an isset function that works (almost) like the one in native PHP: function isset(variablename) {...
6
by: Gunnar Beushausen | last post by:
Hi! I need a class to store the users data (ID, name etc.) that is accessible from anywhere. At application startup the class gets filled with its data about the user. But how can i access...
0
by: Dougal Fair | last post by:
I'm writing a VB.NET application, and I have a lot of general-purpose utility functions that need to be available throughout the program (like functions that perform standard date conversions...
2
by: robin.bruce | last post by:
Hi guys, I just tried to give advice to a colleague who has a problem program in C, and I was interested to hear the thoughts of this forum on the subject. I've been an occasional programmer...
9
by: userblue | last post by:
Hi Does anyone know if there is a way to define what is effectively a single globally visible, enumerated list whilst actually defining the entries across several different modules? or somehow do...
4
by: adodotnet20 | last post by:
I'm developing a Windows application and I'm having some problems in making variable accessible to the whole application. I use VS.NET 2005 and I create a database connection object in the method ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.