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

Passing an object byRef

Hello:

I have an object foUser defined in my main MDI form. I
instantiate this object in the MDI form and pass it into
a child form by reference as:

Dim foUser as New Users.User

Dim formChild as New frmChild(fouser)

The childform's is coded as:

Private foUser as Users.User
Public Sub New (ByRef poUser as Users.User)
fouser = poUser
End Sub

Private sub btnClose_clicked

Dim loUser as New Users.User

foUser = loUser
Me.Closeform

End Sub

However, when the object is returned to the MDI Parent,
it is never changed.

What I am I doing wrong?

Venkat
Nov 20 '05 #1
2 3396
Venkat,

I think your problem is one of the scope of the variables. If you run this
in debug and notice both the values and the memory location of the variables
you may find your problem.
"Venkat Venkataramanan" <th****@hotmail.com> wrote in message
news:1e****************************@phx.gbl...
Hello:

I have an object foUser defined in my main MDI form. I
instantiate this object in the MDI form and pass it into
a child form by reference as:

Dim foUser as New Users.User

Dim formChild as New frmChild(fouser)

The childform's is coded as:

Private foUser as Users.User
Public Sub New (ByRef poUser as Users.User)
fouser = poUser
End Sub

Private sub btnClose_clicked

Dim loUser as New Users.User

foUser = loUser
Me.Closeform

End Sub

However, when the object is returned to the MDI Parent,
it is never changed.

What I am I doing wrong?

Venkat

Nov 20 '05 #2
Hello,

"Venkat Venkataramanan" <th****@hotmail.com> schrieb:
I have an object foUser defined in my main MDI form. I
instantiate this object in the MDI form and pass it into
a child form by reference as:

Dim foUser as New Users.User

Dim formChild as New frmChild(fouser)

The childform's is coded as:

Private foUser as Users.User
Public Sub New (ByRef poUser as Users.User)
fouser = poUser
End Sub

Private sub btnClose_clicked

Dim loUser as New Users.User

foUser = loUser
Me.Closeform

End Sub

However, when the object is returned to the MDI Parent,
it is never changed.


'foUser' is a variable pointing to the instance passed to the class, if you
set 'foUser' to an other instance, this won't change the original object.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3

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

Similar topics

3
by: Andy Read | last post by:
Dear all, I thought I understood passing parameters ByVal and ByRef but I clearly don't! If I define a simple class of: Public Class Person Public Name as String Public Age as Integer End...
2
by: Ryan Malone | last post by:
Passing Dictionary object byref Ive created an ASP class that uses a dictionary object which is filled from a recordset. It passes the object to the propterty of another ASP class byref: ...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
4
by: Sahil Malik [MVP] | last post by:
Okay so now I understand (surprised though) - that WebServices can indeed pass ByRef/ref parameters. All I have to do is mark an integer parameter of a WebMethod as "ref". Funnily enough, this is...
3
by: Scott M. | last post by:
If I pass a reference type ByVal, am I making a copy of the object on the heap or am I making a copy of a pointer to the object on the heap? If I pass a string object (reference type) into a sub...
2
by: Neil Munro | last post by:
I'm having some "type" difficulty in passing a .NET array (byref) to a COM based API (Autodesk Inventor). In VB6 the code to return an array of tolerance values is: Dim ToleranceCount As Long...
4
by: Erik Foreman | last post by:
this is what I have 'variables defined as arrays Dim ceday(), ceti(), ceto(), ceproj(), cenotes() As String Dim cerow As Int32
2
by: Witold Iwaniec via .NET 247 | last post by:
It seems that when you pass an object to a function it is always passed by reference even if it is explicitly declared ByVal. Is it the behavior of VB.Net? Here is sample code from sample Asp.Net...
11
by: John Pass | last post by:
Hi, In the attached example, I do understand that the references are not changed if an array is passed by Val. What I do not understand is the result of line 99 (If one can find this by line...
0
by: VaBa | last post by:
Hi, Need some help.. I have a VBA class module in MS ACCESS. In the same MS ACCESS app, I am calling a .NET DLL (which i have exposed as COM-visible) and passing BYREF an instance of the VBA class...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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:
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...

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.