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... 8 2010
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
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
On Thu, 8 Apr 2004 19:33:48 +0200, "Cor Ligthert"
<no**********@p lanet.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 clsMyApplicatio n
If oApp Is Nothing Then
oApp = New clsMyApplicatio n
End If
Return oMyApp
End Function
And then, wherever I need this object, I just "create" it:
dim oMyApp As clsMyApplicatio n = 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
On Thu, 8 Apr 2004 19:33:48 +0200, "Cor Ligthert"
<no**********@p lanet.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 clsMyApplicatio n
If oApp Is Nothing Then
oApp = New clsMyApplicatio n
End If
Return oMyApp
End Function
And then, wherever I need this object, I just "create" it:
dim oMyApp As clsMyApplicatio n = 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
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****@dougalf air.com> wrote in message
news:40******** ********@news.g oldengate.net.. . On Thu, 8 Apr 2004 19:33:48 +0200, "Cor Ligthert" <no**********@p lanet.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 clsMyApplicatio n If oApp Is Nothing Then oApp = New clsMyApplicatio n End If
Return oMyApp End Function
And then, wherever I need this object, I just "create" it:
dim oMyApp As clsMyApplicatio n = 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
/vaconsharedmemb ers.asp
I hope this helps?
Cor
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****@dougalf air.com> wrote in message
news:40******** ********@news.g oldengate.net.. . On Thu, 8 Apr 2004 19:33:48 +0200, "Cor Ligthert" <no**********@p lanet.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 clsMyApplicatio n If oApp Is Nothing Then oApp = New clsMyApplicatio n End If
Return oMyApp End Function
And then, wherever I need this object, I just "create" it:
dim oMyApp As clsMyApplicatio n = 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
/vaconsharedmemb ers.asp
I hope this helps?
Cor
"Dougal Fair" <do****@dougalf air.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
"Dougal Fair" <do****@dougalf air.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 $arr=array(); (syntax err)
2) global $arr; in "main", the var isn't global
3) global $arr; in function, the array is cleared each time
|
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 function.
DO: $var = null;
DONT DO: unset($var);
|
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 which one.
if I do:
|
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) {
return(typeof(eval("window."+variablename))!='undefined');
}
I use it like if(isset('myVar') { alert(myVar); }
|
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 this data from all other classes?
Normally to get access, i would have to say something like UserData *UD =
new UserData; But this way a new class gets instantieted. What can i do to
| |
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 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...
|
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 in C for about a year now, so by no
means an expert, so it would be good to know if I'm leading my
colleague down the wrong path.
|
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 a similar thing with macros.
Details:
I have a c project to fit into a small microprocessor and need to save
some ram. I have a significant number of flags all over the place that
currently use whole byte storage. I thought if I had a way to...
|
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 private void
connect_Click(object sender, EventArgs e). That object I create seems
to be accessible only within that method, how do I make it accessible
to the whole application, just like I have access to mytextbox.text
throughout my tabbed...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |