473,407 Members | 2,359 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,407 software developers and data experts.

How to access an object's private variables (VB .NET)

121 100+
I have a class (call it "A") that has an object (call it "B") whose code I wrote. I want A to be able to access B's private variables.

In C++ (and probably C#), I would just type "friend class A;" in the definition of B. However, this doesn't seem to work, and from what I can tell from MSDN, the Friend keyword in VB doesn't work that way.

There has to be a way to do this... anyone know how?
May 21 '08 #1
5 1510
Plater
7,872 Expert 4TB
I think if you label the fields as "protected" and not as "private" then the "owning" object can manipulate the fields but nobody else can?
May 21 '08 #2
Sick0Fant
121 100+
I think if you label the fields as "protected" and not as "private" then the "owning" object can manipulate the fields but nobody else can?
Declaring the field Protected didn't seem to make any difference. I tried "Protected Friend" which gave the class access to the object's field regardless of whether or not it owned the instance, which isn't quite what I want.
May 21 '08 #3
Plater
7,872 Expert 4TB
Might be a namsspace allowance or something then. I don't remember exactly what protected did.
Hit f1 with protected highlighted, maybe there's something else there that could help you?
May 21 '08 #4
Sick0Fant
121 100+
Protected lines up pretty well with what it means in C, in that protected fields are accessible by derived objects. Friend means that the field is accessible to all classes in the assembly.

I'd like to restrict access to all classes except for a certain one.
May 21 '08 #5
Plater
7,872 Expert 4TB
Could you put the two classes in their own assembly and seal it up? (I think you can do that right? You can seal classes so they cannot be derrived from, I think you can do that to a namespace?)
May 21 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: vipul DotNet | last post by:
hi, which all are the access specifiers in vb.net thank you vipul
17
by: Woody Splawn | last post by:
I am finding that time after time I have instances where I need to access information in a variable that is public. At the same time, the books I read say that one should not use public variables...
3
by: John C Kirk | last post by:
One odd thing I've come across - if you declare a private variable in a class, it is exposed to other instances of that same class. To replicate this behaviour, create a class like this: ...
0
by: albean | last post by:
I I have a number of VB COM components used in ASP pages that access some intrinsic ASP objects. Basically we would get the context from COMSVCSLib and from there get the ASP Request and Response...
10
by: Goran Djuranovic | last post by:
Hi all, Does anyone know how to declare a variable in a class to be accessible ONLY from a classes instantiated within that class? For example: ************* CODE ***************** Public...
2
by: Rob Long | last post by:
Hi there Is there any way to access private variables directly from within a priviliged function? I have a situation where the priviliged function's execution context contains variables of the...
13
by: PragueExpat | last post by:
I (think) that I've come up with a pattern that I haven't seen in any publications so far and I would like some feedback. Basically, I was looking for a way to inherit private functions and I came...
1
by: Thomas 'PointedEars' Lahn | last post by:
Gregor Kofler wrote: I am curious, why did you choose to use a factory instead of a constructor? It's a closure and `privateVar' in privateFunc() is bound to the execution context of foo(),...
1
by: agendum97 | last post by:
On Jun 26, 4:53*pm, Gregor Kofler <use...@gregorkofler.atwrote: If possible for your scenario, you could potentially use eval for this. For example: function MyClass(val) { var printIt =...
4
by: AlarV | last post by:
I want to create an array of pointers, for my class. Each pointer will in fact be the 'head' of a dynamic list. I don't know the size of the array and it has to be given by the user. So my...
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: 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:
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
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
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...
0
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...
0
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...

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.