473,385 Members | 1,720 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.

"Shared" members as globals?

MyWebProject.MyWebForm1.someset.somedata is a datatable
within a dataset. Displays quite nicely, too. Now I want
to use the same data in MyWebProject.MyWebForm2. Being a
old, er, experienced Java programmer, I thought I could
write this as a member of MyWebForm1:

Public Shared Function getSomeData() As DataTable
getSomeData = somedata
End Function

so in MyWebForm2 I could have:

Dim quelquedata As DataTable
quelquedata = MyWebForm1.getSomeData()

Could someone point out how to accomplish this the RIGHT
way, as the above clearly doesn't work?
Nov 18 '05 #1
6 1410
The Shared keyword in VB is equivalent to the static keyword in C-like
languages. It's hard to tell from the snippet that you have here, but as
long as you are referencing the name of the class, and the contents of the
method do not include any instance variables, then it should work just fine.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Ross" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
MyWebProject.MyWebForm1.someset.somedata is a datatable
within a dataset. Displays quite nicely, too. Now I want
to use the same data in MyWebProject.MyWebForm2. Being a
old, er, experienced Java programmer, I thought I could
write this as a member of MyWebForm1:

Public Shared Function getSomeData() As DataTable
getSomeData = somedata
End Function

so in MyWebForm2 I could have:

Dim quelquedata As DataTable
quelquedata = MyWebForm1.getSomeData()

Could someone point out how to accomplish this the RIGHT
way, as the above clearly doesn't work?

Nov 18 '05 #2
Ross,

The Shared keyword means that the method may be used from multiple
instances of an object. In your case, the getSomeData() method is a member
of the WebForm1 class and is not accessible by the WebForm2 class.
However, even so, the WebForm1 class instance is no longer available anyway
because of page lifecycle.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
Content-Class: urn:content-classes:message
From: "Ross" <an*******@discussions.microsoft.com>
Sender: "Ross" <an*******@discussions.microsoft.com>
Subject: "Shared" members as globals?
Date: Wed, 3 Dec 2003 13:12:30 -0800
Lines: 17
Message-ID: <02****************************@phx.gbl>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcO54imEkxwCaCjlS4Ota3r2Kg3dvw==
Newsgroups: microsoft.public.dotnet.framework.aspnet
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:194851
NNTP-Posting-Host: tk2msftngxa12.phx.gbl 10.40.1.164
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

MyWebProject.MyWebForm1.someset.somedata is a datatable
within a dataset. Displays quite nicely, too. Now I want
to use the same data in MyWebProject.MyWebForm2. Being a
old, er, experienced Java programmer, I thought I could
write this as a member of MyWebForm1:

Public Shared Function getSomeData() As DataTable
getSomeData = somedata
End Function

so in MyWebForm2 I could have:

Dim quelquedata As DataTable
quelquedata = MyWebForm1.getSomeData()

Could someone point out how to accomplish this the RIGHT
way, as the above clearly doesn't work?


Nov 18 '05 #3
Chris,

You are correct in a way. I missed the Public keyword. Under normal
object-oriented situations, the method would be available to the second
class. However, in this instance, the Webform1 instance no longer exists.
Page lifecycle prevents access to the instance.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "Chris Jackson" <chrisjATmvpsDOTorgNOSPAM>
References: <02****************************@phx.gbl>
Subject: Re: "Shared" members as globals?
Date: Wed, 3 Dec 2003 16:24:57 -0500
Lines: 37
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#y*************@tk2msftngp13.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 208.252.52.2
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFT NGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!tk2msftngp13.phx.gblXref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:194857
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

The Shared keyword in VB is equivalent to the static keyword in C-like
languages. It's hard to tell from the snippet that you have here, but as
long as you are referencing the name of the class, and the contents of the
method do not include any instance variables, then it should work just fine.
--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Ross" <an*******@discussions.microsoft.com> wrote in message
news:02****************************@phx.gbl...
MyWebProject.MyWebForm1.someset.somedata is a datatable
within a dataset. Displays quite nicely, too. Now I want
to use the same data in MyWebProject.MyWebForm2. Being a
old, er, experienced Java programmer, I thought I could
write this as a member of MyWebForm1:

Public Shared Function getSomeData() As DataTable
getSomeData = somedata
End Function

so in MyWebForm2 I could have:

Dim quelquedata As DataTable
quelquedata = MyWebForm1.getSomeData()

Could someone point out how to accomplish this the RIGHT
way, as the above clearly doesn't work?



Nov 18 '05 #4

"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> wrote in message
news:Fc**************@cpmsftngxa06.phx.gbl...
Ross,

The Shared keyword means that the method may be used from multiple
instances of an object. In your case, the getSomeData() method is a member of the WebForm1 class and is not accessible by the WebForm2 class.
However, even so, the WebForm1 class instance is no longer available anyway because of page lifecycle.


Ummm, no.

What the poster is attempting will work fine.
Public Shared Function getSomeData() As DataTable
getSomeData = somedata
End Function
The Shared method belongs to the MyWebForm1 type, not to any particular
instance. It will be available from any method in any type at any time.

Ross, what error are you getting?

David
Nov 18 '05 #5
You are, of course, correct. As Chris stated earlier, it does work just
like static in C#. My mistake.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "David Browne" <davidbaxterbrowne no potted me**@hotmail.com>
References: <02****************************@phx.gbl> <Fc**************@cpmsftngxa06.phx.gbl>Subject: Re: "Shared" members as globals?
Date: Wed, 3 Dec 2003 16:01:02 -0600
Lines: 32
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#H*************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 199.34.81.136
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:194875
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> wrote in message
news:Fc**************@cpmsftngxa06.phx.gbl...
Ross,

The Shared keyword means that the method may be used from multiple
instances of an object. In your case, the getSomeData() method is a

member
of the WebForm1 class and is not accessible by the WebForm2 class.
However, even so, the WebForm1 class instance is no longer available

anyway
because of page lifecycle.


Ummm, no.

What the poster is attempting will work fine.
Public Shared Function getSomeData() As DataTable
getSomeData = somedata
End Function
The Shared method belongs to the MyWebForm1 type, not to any particular
instance. It will be available from any method in any type at any time.

Ross, what error are you getting?

David


Nov 18 '05 #6
You are, of course, correct. As Chris stated earlier, it does work just
like static in C#. My mistake.

Jim Cheshire, MCSE, MCSD [MSFT]
Developer Support
ASP.NET
ja******@online.microsoft.com

This post is provided as-is with no warranties and confers no rights.

--------------------
From: "David Browne" <davidbaxterbrowne no potted me**@hotmail.com>
References: <02****************************@phx.gbl> <Fc**************@cpmsftngxa06.phx.gbl>Subject: Re: "Shared" members as globals?
Date: Wed, 3 Dec 2003 16:01:02 -0600
Lines: 32
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#H*************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.framework.aspnet
NNTP-Posting-Host: 199.34.81.136
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:194875
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
"Jim Cheshire [MSFT]" <ja******@online.microsoft.com> wrote in message
news:Fc**************@cpmsftngxa06.phx.gbl...
Ross,

The Shared keyword means that the method may be used from multiple
instances of an object. In your case, the getSomeData() method is a

member
of the WebForm1 class and is not accessible by the WebForm2 class.
However, even so, the WebForm1 class instance is no longer available

anyway
because of page lifecycle.


Ummm, no.

What the poster is attempting will work fine.
Public Shared Function getSomeData() As DataTable
getSomeData = somedata
End Function
The Shared method belongs to the MyWebForm1 type, not to any particular
instance. It will be available from any method in any type at any time.

Ross, what error are you getting?

David


Nov 18 '05 #7

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

Similar topics

10
by: Berthold Hoellmann | last post by:
Hello, When I use ./configure --with-thread --with-fpectl --with-signal-module \ --with-pymalloc --enable-shared --with-cxx=g++ make test on 2.3.3 I get
2
by: santa19992000 | last post by:
Confusing th eword with "library", "shared library" and how to use these things in real C project, is there any small example I can take a look. Thanks.
2
by: Jenna Schmidt | last post by:
I know that one of the benefits of using "Shared" methods is you do not explicitly have to Dim as New object to access the method. Are there some other implications with memory and concurrency...
3
by: Henri | last post by:
Hi, Sorry for my bad English. Could you tell me if the context of a member declared as Shared is limited to the instance of the page the object that owns this member is declared in, or does it...
2
by: John Granade | last post by:
I'm looking for the best way to make a dataset available from multiple Windows forms. The dataset is created from an XML file. I have a main form (frmMain) that loads the dataset and reads the...
1
by: David Sanschagrin | last post by:
(I previously posted this problem on vb.general.discussion but I've been told that this question is more related to VB.NET than VB6 and so that I should post that here.) I'm trying to call a...
2
by: HmFireBall | last post by:
Hi, This is a question about a shared property in ASP.NET Imagine there's an assembly called my.dll that is in the /bin directory of several websites. This assembly contains a class with a...
3
by: Kenneth Kahl | last post by:
Hello, I would like to call a C++ programm out of Java with help of JNI. By the followed command I created a "shared library": g++ -shared -o libcalculate.so rechner.cpp When I create an...
3
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte()...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.