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

References to references in VB .NET

I have 2 windows forms. In the first form I have a reference to an object. I
want to assign an object to that reference from the second form. If I pass
this reference to the new(...) method of the second form ByRef, I can easily
assign an object to the reference in the first form, as long as I do it in
the new(...) method.

However, I don't want to make this assignment in the constructor of the
second form. So I thought that I would create a second reference(of the same
type as the first) in the second form and assign the reference passed from
the first form to this reference in the second form. I would then try to
assign an object to the reference in the second form, hoping that it would in
effect be changing what the reference in the first form was pointing to. (In
my C days this was getting a pointer to a pointer).

But it doesn't work as expected. I can't make the reference from the first
form point to an object that I've assigned to the reference in the second
form, even though I assigned one reference to the other in the new(...)
method, which took the first reference ByRef in the constructors parameter
list.

Is there a way in VB .NET to create a reference to a reference so that I can
delay assignment of an object to a reference passed ByRef from the new(...)
to a different place in the second form?

Michael
--
Michael Hockstein
Nov 21 '05 #1
2 1062
Hi Michael
This is because what you have here is to references not just one .when
you pass the ref parameter to the second form and assign it to a new
reference . you now get 2 references pointing to the same object . So ,when
you change the second one ( that of form two ) to point to new object ,
that of course will not make the first reference ( of from one ) point to
that new object and it will still point to the old one . In c and C++
we can explicitly declare pointers and we can declare even declare
pointers to them ** , which would have solved the problem of course .
however , here we can only play with references when passing parameters .
so you can either pass this reference back to from one ( so it would be
changes ) . or you can just override the values of the object pointed to by
first reference by the values of the second object that is pointed to by
the new ref. this way you will have same values gotten by both references,
however still they are to different objects ( just holding the same value
. Hope this helps

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 21 '05 #2
So, unlike C/C++, in VB .NET, I can't create a reference to a reference. I
can pass an object Byref so that I can manipulate the original object.
However, I can't pass a reference to that object and manipulate that
reference so that it ends up pointing to another object.

Wonder VB leaves out this ability.

Thanks for your help

Michael
"Mohamoss" wrote:
Hi Michael
This is because what you have here is to references not just one .when
you pass the ref parameter to the second form and assign it to a new
reference . you now get 2 references pointing to the same object . So ,when
you change the second one ( that of form two ) to point to new object ,
that of course will not make the first reference ( of from one ) point to
that new object and it will still point to the old one . In c and C++
we can explicitly declare pointers and we can declare even declare
pointers to them ** , which would have solved the problem of course .
however , here we can only play with references when passing parameters .
so you can either pass this reference back to from one ( so it would be
changes ) . or you can just override the values of the object pointed to by
first reference by the values of the second object that is pointed to by
the new ref. this way you will have same values gotten by both references,
however still they are to different objects ( just holding the same value
. Hope this helps

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 21 '05 #3

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

Similar topics

17
by: Tom | last post by:
The motivation for references seems clear: stop people from using nasty pointers when all they really want is a reference to an object. But C++ references are so inadequate that I'm still using...
22
by: xmp333 | last post by:
Hi All, I am trying to hide my JavaScript source. The method I chose was to keep all the important source in a password protected folder, and then use a SRC="folder/script.js" to include it...
33
by: JKop | last post by:
I understand variables/objects and pointer variables perfectly: int X = 5; int* pX = &X; *pX = 4; int** ppX = &pX:
2
by: S. van Beek | last post by:
Dear reader, For removing a reference in the VBA reference form I receive from Doug Steele the following code: ........... References.Remove refCurr
11
by: codebloatation | last post by:
I know how to use references but i DO not get WHY they exist other than to add to the language. Are they actually needed for anything?
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
30
by: jeremygetsmail | last post by:
I've got an adp (Metrix.adp) with a reference to another adp (InteractSQL.adp). InteractSQL sits on a server, and is refered to by all of the clients (Metrix), which sit on the client machines...
3
by: DonJefe | last post by:
Does anyone have experience using project->project references in large solutions? What are the plus/minuses that you have found? Currently, we are using the binary assembly references for our...
9
by: igor.kulkin | last post by:
References is a relatively basic feature of C++ language. It might be a good thing to think of references as aliases to the variables. However it's good to think of references this way when you...
3
by: CenturionX | last post by:
Hello everybody: I'd like to know what references in my vba code are used or not. I work in a code made by another person previously, i founded to many references and i believe that someones...
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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,...

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.