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

Do Object references exist in VB????


Say I pass an object ByRef. And I want to store a reference to that
object. How do I do this?
Arturo Hernandez

Nov 21 '05 #1
9 7376
dim myObject as Object

myProcedure(myObject)
Private Sub myProcedure (byref obj as Object)
'now you have a reference to myObject in your sub that you can use for
whatever. If you change obj to reference a different object then myObjec in
your calling module/class will also be changed to the new object.
...

end sub
--
Dennis in Houston
"ar*******@hotmail.com" wrote:

Say I pass an object ByRef. And I want to store a reference to that
object. How do I do this?
Arturo Hernandez

Nov 21 '05 #2
Arturo,
Say I pass an object ByRef. And I want to store a reference to that
object. How do I do this?

I am not sure if I understand your answer, however I assume that you want to
pass an object by value (a copy of the reference of the object is than
passed as the value).

I hope this helps,

Cor
Nov 21 '05 #3
<ar*******@hotmail.com> schrieb:
Say I pass an object ByRef. And I want to store a reference to that
object. How do I do this?


There are two kinds of types in .NET: Reference types and value types.
Objects which are instances of a value type are always copied when being
assigned to another variable whereas assigning a reference to an instance of
a reference type will create a new reference. A more detailed explanation
of what's going on when passing objects to a method can be found here:

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/25064a4fedd36633>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #4

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OP**************@tk2msftngp13.phx.gbl...
<ar*******@hotmail.com> schrieb:
Say I pass an object ByRef. And I want to store a reference to that
object. How do I do this?
There are two kinds of types in .NET: Reference types and value types.
Objects which are instances of a value type are always copied when being
assigned to another variable whereas assigning a reference to an instance
of a reference type will create a new reference. A more detailed
explanation of what's going on when passing objects to a method can be
found here:


Dont you mean that Objects which are instances of a value type which are
passed by value are copies of the original object and therefore when values
are assigned TO them it is to the copy not the original.

In your text above, it appears as if you are saying that these objects which
are passed by value are copied before the value can be assigned, which of
course would seem to be irrelevant because if you only assigned a passed
objects value then there would be no need to copy it.

Make sense ??

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/25064a4fedd36633>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
"Mr Newbie" <he**@now.com> schrieb:
Say I pass an object ByRef. And I want to store a reference to that
object. How do I do this?


There are two kinds of types in .NET: Reference types and value types.
Objects which are instances of a value type are always copied when being
assigned to another variable whereas assigning a reference to an instance
of a reference type will create a new reference. A more detailed
explanation of what's going on when passing objects to a method can be
found here:


Dont you mean that Objects which are instances of a value type which are
passed by value are copies of the original object and therefore when
values > are assigned TO them it is to the copy not the original.


You are right -- I was referrint to variable assignment, not passing the
variable in a method's parameter.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #6

Herfried K. Wagner [MVP] wrote:
<ar*******@hotmail.com> schrieb:
Say I pass an object ByRef. And I want to store a reference to that
object. How do I do this?


There are two kinds of types in .NET: Reference types and value types.
Objects which are instances of a value type are always copied when being
assigned to another variable whereas assigning a reference to an instance of
a reference type will create a new reference. A more detailed explanation
of what's going on when passing objects to a method can be found here:

<URL:http://groups.google.de/group/microsoft.public.dotnet.languages.vb/msg/25064a4fedd36633>


This is an example:

Class HumpaLumpa

Public Sub CoolSub(ByRef pCar As Car)
Me.vCar=pCar
End Sub
Nov 21 '05 #7
<ar*******@hotmail.com> schrieb:
Class HumpaLumpa

Public Sub CoolSub(ByRef pCar As Car)
Me.vCar=pCar
End Sub
.
.
.
Me.vCar.WindowDown=True 'did the original object get changed or
just a copy of it?
The original object because 'Car' is a class and thus a reference type.
This is a second example:

Class HumpaLumpa

Public Sub CoolSub(ByRef pCar As Integer)
Me.vCar=pCar
End Sub
.
.
.
Me.vCar=22 'did the original variable get changed or
just a copy of it?


Just a copy of it. The assignment 'Me.vCar = pCar' will create a copy of
'pCar''s value and assign it to 'vCar'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #8
But, the end result is that the vChar property will be changed in the
original object.

Object references are just that. They only point to the actual object. If
you pass an object reference ByRef it still is just a pointer to the object.
The only difference is that the original object reference will change if you
assign the passed reference. For example:

Private sub Foo
Dim Bar as New Bar
SetFoo(Bar)

'When you come back here Bar now points to the new object created in SetFoo
End Sub
Private Sub SetFoo(byRef Bar as Bar)
Bar.Foo = "New Value" ' Changes the property in the original object
created in Foo
Bar = New Bar ' Creates a new object
End Sub

If parameter Bar in the SetFoo sub was defined as ByVal then the original
Bar variable in Sub Foo will not change and still point to the original
object.

NOTE: This is horrible programming but does show the difference on object
references passed as ByRef or ByVal.

"Herfried K. Wagner [MVP]" wrote:
<ar*******@hotmail.com> schrieb:
Class HumpaLumpa

Public Sub CoolSub(ByRef pCar As Car)
Me.vCar=pCar
End Sub
.
.
.
Me.vCar.WindowDown=True 'did the original object get changed or
just a copy of it?


The original object because 'Car' is a class and thus a reference type.
This is a second example:

Class HumpaLumpa

Public Sub CoolSub(ByRef pCar As Integer)
Me.vCar=pCar
End Sub
.
.
.
Me.vCar=22 'did the original variable get changed or
just a copy of it?


Just a copy of it. The assignment 'Me.vCar = pCar' will create a copy of
'pCar''s value and assign it to 'vCar'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #9
>Just a copy of it. The assignment 'Me.vCar = pCar' will create a copy of
'pCar''s value and assign it to 'vCar'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>


Thank you, this is a little bit confusing aspect of VB. But I think I
got it.

Nov 21 '05 #10

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

Similar topics

4
by: Mark D. Anderson | last post by:
About a month ago Richard Cornford did an interesting analysis of a memory leak in jscript (internet explorer) when there are "circular" references between DOM objects and (real) jscript objects:...
8
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
5
by: Varangian | last post by:
ImageButton ship; ship = new ImageButton; for (int i=0; i<5; i++) { ship.ImageUrl = pathofImage; ship.ID = "ShipNo" + i.ToString(); ship.Click += new...
4
by: gg9h0st | last post by:
i worte a simple code below. ------------------------------------------------------------------------------------ #include "stdafx.h" class Object { public: int a;
2
by: Ivor Somerset | last post by:
Hello, In my ASP code I sometimes write functions that return an object (generally an XML node). Such a function is invoked this way: Set Object1 = MyFunction(SomeValue) And at the end of...
2
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
10
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine...
2
by: Veloz | last post by:
Hiya My question is whether or not you should associated related objects in your software using a scheme of id's and lookups, or wether objects should actually hold actual object references to...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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
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.