473,387 Members | 1,624 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.

retrieving private property from shared public function

In a 2.0 vb code class, I have a private property and a shared public function

The property value has already been passed into the class, now I am trying to use a public finction which also needs the property
value.

How can I use the private property from within the shared public function, without having to pass the property value back into the
class again?

attempting to use the value now returns this error message:
-----------------------------------------------------------------------------

"Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance
of the class."

Feb 9 '06 #1
2 2211
1) Make the property public. (Although it might have been private for a
reason).
2) Make the property internal (or in the case of VB, probably a "friend").
3) Use reflection to get access to the private property. (The program will
slow because reflection is slower than direct access).

You have to ask yourself, why are you trying to access a private member.
Usually things that are private as such for a reason, otherwise they would
have been exposed to the world.

"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
In a 2.0 vb code class, I have a private property and a shared public
function

The property value has already been passed into the class, now I am trying
to use a public finction which also needs the property value.

How can I use the private property from within the shared public function,
without having to pass the property value back into the class again?

attempting to use the value now returns this error message:
-----------------------------------------------------------------------------

"Cannot refer to an instance member of a class from within a shared method
or shared member initializer without an explicit instance of the class."

Feb 9 '06 #2
A shared member can't access an instance member with having an instance.

so if you have

public class Test
private name as string

public shared sub DoSomething()
'can't access name from here since name is an instance member
end sub
end class

It doesn't make sense why you'd want to, so perhaps if you explain what ur
tryin gto achieve.

karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Jon Paal" <Jon[ nospam ]Paal @ everywhere dot com> wrote in message
news:%2***************@TK2MSFTNGP14.phx.gbl...
In a 2.0 vb code class, I have a private property and a shared public
function

The property value has already been passed into the class, now I am trying
to use a public finction which also needs the property value.

How can I use the private property from within the shared public function,
without having to pass the property value back into the class again?

attempting to use the value now returns this error message:
-----------------------------------------------------------------------------

"Cannot refer to an instance member of a class from within a shared method
or shared member initializer without an explicit instance of the class."

Feb 9 '06 #3

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

Similar topics

5
by: YellowDog | last post by:
I want to use a property without a private data member. This is supposed to be legal, except that I get an Stack Overflow Exception when I implicity use the set method. Here's the code: Option...
1
by: Jeffrey B. Holtz | last post by:
I'm trying to get the Name of the USB device pluged in from the RegisterDeviceNotification that I've used P/Invoke to marshal. I have seen a similar posting on the VisualBasic newgroups but I do...
2
by: Boban Dragojlovic | last post by:
I'm building a complex web-based reservations system. Gathering the user's data requires between 8 and 15 pages (depending on which options they are interested in). I use the "Session" object to...
1
by: tangus via DotNetMonster.com | last post by:
Hello all, I'm really struggling with getting some Active Directory code to work in ASP.NET. Can you please provide assistance? I am executing the following code: Dim enTry As DirectoryEntry =...
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...
3
by: WStoreyII | last post by:
I have a Collection Class That I am Creating , In This Collection Class I have a default Property Item. My Problem is this I have about twenty different Criterias that can be used as a value...
8
by: Chad | last post by:
To anyone who is smarter than I am when it comes to WMI: Here is what I am trying to do: 1) Detect a USB pen drive when it is inserted 2) Retrieve the drive letter of the pen drive 3) Check...
4
by: rognon | last post by:
Hi there, I'm trying to do something, but I don't know if it's possible. Basically, I want to have a public static class method that could access a private object's method. I would like to be able...
1
by: Olaf Rabbachin | last post by:
Hi folks, I'd like to retrieve default values for properties (of a user control) via code instead of having string-constants. Consider the following (simplified) property: Private _MyColor...
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
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:
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
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.