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

Shared Public Variables and Shared Methods

I have a Shared varibale in a base class and all the Shared methods in the
sub-classes use it (and CHANGE it).
I thought I was saving myself the "trouble" of Dimming this variable inside
each Shared method.
But now I wonder if I will have a problem in a multi-user environment with
code that changes this variable.

Can someone please review this sample code and let me know if it is an
issue?
Also what is the best way to clean it up? Dim the variable inside each
method?

Thanks!

----------------------------------------------------------------------
Sample code:

Base Class:

'this variable never changes once it is established on app start. Is
this OK?
Public Shared mVar1 As String

'used in sub-classes and is changed inside each method call. Is this a
huge problem?
Public Shared mVar2 As String
Sub-Class:

'method 1:
Public Shared Function Foo() As String
mVar2 = "Some string "
mVar2 &= "some more "
mVar2 &= "and more"
Return mVar2
End Function
'method 2:
Public Shared Function Bar() As String
mVar2 = "Some other string "
mVar2 &= "some more "
mVar2 &= "and more"
Return mVar2
End Function

'methods 3-10 do similar things.
--
Joe Fallon


Nov 18 '05 #1
3 1794
Hi Joe:

As you suspect, multiple user's requests might be modifying the
variable at the same time, leading to unexpected results. The easiest
solution is to use a local variable inside of each shared function.

--
Scott
http://www.OdeToCode.com
On Thu, 15 Jul 2004 12:22:04 -0400, "Joe Fallon"
<jf******@nospamtwcny.rr.com> wrote:
I have a Shared varibale in a base class and all the Shared methods in the
sub-classes use it (and CHANGE it).
I thought I was saving myself the "trouble" of Dimming this variable inside
each Shared method.
But now I wonder if I will have a problem in a multi-user environment with
code that changes this variable.

Can someone please review this sample code and let me know if it is an
issue?
Also what is the best way to clean it up? Dim the variable inside each
method?

Thanks!

----------------------------------------------------------------------
Sample code:

Base Class:

'this variable never changes once it is established on app start. Is
this OK?
Public Shared mVar1 As String

'used in sub-classes and is changed inside each method call. Is this a
huge problem?
Public Shared mVar2 As String
Sub-Class:

'method 1:
Public Shared Function Foo() As String
mVar2 = "Some string "
mVar2 &= "some more "
mVar2 &= "and more"
Return mVar2
End Function
'method 2:
Public Shared Function Bar() As String
mVar2 = "Some other string "
mVar2 &= "some more "
mVar2 &= "and more"
Return mVar2
End Function

'methods 3-10 do similar things.


Nov 18 '05 #2
Scott,
Thanks for the bad news. <g>
At least I can recover from this mistake!

I think I will go with:

Public Shared Function Bar() As String
Return "Some other string " &_
"some more " &_
"and more"
End Function

--
Joe Fallon
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:l7********************************@4ax.com...
Hi Joe:

As you suspect, multiple user's requests might be modifying the
variable at the same time, leading to unexpected results. The easiest
solution is to use a local variable inside of each shared function.

--
Scott
http://www.OdeToCode.com
On Thu, 15 Jul 2004 12:22:04 -0400, "Joe Fallon"
<jf******@nospamtwcny.rr.com> wrote:
I have a Shared varibale in a base class and all the Shared methods in thesub-classes use it (and CHANGE it).
I thought I was saving myself the "trouble" of Dimming this variable insideeach Shared method.
But now I wonder if I will have a problem in a multi-user environment withcode that changes this variable.

Can someone please review this sample code and let me know if it is an
issue?
Also what is the best way to clean it up? Dim the variable inside each
method?

Thanks!

----------------------------------------------------------------------
Sample code:

Base Class:

'this variable never changes once it is established on app start. Is
this OK?
Public Shared mVar1 As String

'used in sub-classes and is changed inside each method call. Is this ahuge problem?
Public Shared mVar2 As String
Sub-Class:

'method 1:
Public Shared Function Foo() As String
mVar2 = "Some string "
mVar2 &= "some more "
mVar2 &= "and more"
Return mVar2
End Function
'method 2:
Public Shared Function Bar() As String
mVar2 = "Some other string "
mVar2 &= "some more "
mVar2 &= "and more"
Return mVar2
End Function

'methods 3-10 do similar things.

Nov 18 '05 #3
guy
Why does the variable have to be shared?
can it not be a Public or Protected Variable/Property?

hth

guy

"Joe Fallon" wrote:
I have a Shared varibale in a base class and all the Shared methods in the
sub-classes use it (and CHANGE it).
I thought I was saving myself the "trouble" of Dimming this variable inside
each Shared method.
But now I wonder if I will have a problem in a multi-user environment with
code that changes this variable.

Can someone please review this sample code and let me know if it is an
issue?
Also what is the best way to clean it up? Dim the variable inside each
method?

Thanks!

----------------------------------------------------------------------
Sample code:

Base Class:

'this variable never changes once it is established on app start. Is
this OK?
Public Shared mVar1 As String

'used in sub-classes and is changed inside each method call. Is this a
huge problem?
Public Shared mVar2 As String
Sub-Class:

'method 1:
Public Shared Function Foo() As String
mVar2 = "Some string "
mVar2 &= "some more "
mVar2 &= "and more"
Return mVar2
End Function
'method 2:
Public Shared Function Bar() As String
mVar2 = "Some other string "
mVar2 &= "some more "
mVar2 &= "and more"
Return mVar2
End Function

'methods 3-10 do similar things.
--
Joe Fallon


Nov 18 '05 #4

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

Similar topics

6
by: Paul | last post by:
Hi. Just trying to find out the best approach as I beleive it might give me problems later on down the road. I have an ASP.NET application which references a shared database class which...
10
by: John Brock | last post by:
I have a base class with several derived classes (I'm writing in VB.NET). I want each derived class to have a unique class ID (a String), and I want the derived classes to inherit from the base...
10
by: darrel | last post by:
I'm still trying to sort out in my head the differences between public and shared when referring to declaring properties or variables. This is my understanding: shared - akin to a 'global'...
15
by: Rob Nicholson | last post by:
A consequence of the ASP.NET architecture on IIS has just hit home with a big thud. It's to do with shared variables. Consider a module like this: Public Module Functions Public GlobalName As...
8
by: Mark Kamoski | last post by:
Hi Everyone-- Please help. What are the implications, (in terms of memory, application footprint, resource use, threading, and so forth), of using Shared methods? These Shared classes raise...
1
by: Edward | last post by:
I have trouble with some of the concepts of OOP, and am struggling currently with Private Shared Functions. I think I understand Private (not available outside the class). I think I understand...
8
by: gemel | last post by:
I have been reading sime material in .NET that throws some doubt on my understanding of shared procedures. With regard to object programming I assumed that variables declared within a class were...
15
by: Laser Lu | last post by:
I was often noted by Thread Safety declarations when I was reading .NET Framework Class Library documents in MSDN. The declaration is usually described as 'Any public static (Shared in Visual...
11
by: eBob.com | last post by:
I have this nasty problem with Shared methods and what I think of as "global storage" - i.e. storage declared outside of any subroutines or functions. In the simple example below this "global"...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
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.