473,883 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2243
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******** *******@TK2MSFT NGP14.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******** *******@TK2MSFT NGP14.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
4001
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 Explicit Option Strict On Imports System
1
11270
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 not know how to translate the ReDim that occurs there into C#. Or wither this will actually give me what I'm looking for. The code I'm posting seems to work although I don't know how to set the length of the name correctly in the...
2
2398
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 store the various elements as the user moves through the pages. Rather than storing the preferences directly in the Session object (e.g. Session("LastName") = ...), I created a class <Serializable()> Public Class ReservationInfo
1
3899
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 = New DirectoryEntry("LDAP://domain") Dim mySearcher As New DirectorySearcher(enTry) Dim resEnt As SearchResult mySearcher.Filter = ("(objectClass=*)") mySearcher.SearchScope = SearchScope.Subtree
1
23299
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 Shared (available without having to instantiate a class). So how could a Private Shared Function be called? Why give it this particular scope?
3
3209
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 in searching for this item. So i figured that i could use overloaded item property's, however it seems that i may not have an overloaded property of the same value type
8
8500
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 for a specific folder on the pen drive I keep receiving an error message that reads: An unhandled exception of type 'System.ExecutionEngineException'
4
5797
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 to do : Class.method(InstanceOfClass); The method would then access a private function from Class by doing something like
1
1149
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 as Color <DefaultValue(GetType(Color), "1, 2, 3")_
0
9933
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9779
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,...
0
11114
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, 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...
1
10835
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10407
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7960
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5787
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...
1
4605
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
2
4205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.