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

Storing a reference to a value type

Hello Group,

I used something like this in a program of mine:

public class WorkObject

private _myproperty as string

public property MyProperty as string()
get,set trivial
end property

public sub new(byval mp as string)
MyProperty = mp
end sub

end class

public class Work

private _refWorkObject as new WorkObject(String.empty)

public sub new(ByRef wo as WorkObject)
wo = _refWorkObject
DoStuff()
end sub

private sub DoStuff()
'In the real program, DoStuff() gets called after some user
interaction
'and not by the constructor like in this simplified example.
'So I cant pass wo as a parameter, I have to store it as a private
variable

_refWorkObject.MyProperty = "new value"
end sub

end class

public class main

public sub main()

dim IWantThisToChange as WorkObject
dim w as new Work(IWantThisToChange)

system.console.out.writeline(IWantThisToChange.MyP roperty) 'results
in "new value"

end sub

end class
Now, all of this works fine as long as I use a reference type with public
fields / properties (workobject in this case). If I try the same thing with
System.Guid instead of WorkObject, it obviously won't work. Do I really have
to wrap it, or is there some funky pointer like syntax in VB.NET that I just
haven't found yet.

I want something like

public class Work

private _refuid as new Guid()

public sub new(ByRef uid as Guid)
uid = _refuid
DoStuff()
end sub

private sub DoStuff()
_refuid = getdesiredvalue() 'With the variable that was passed into
the work constructor taking the new value of _refuid

end sub

end class
Any help is highly appreciated.


Nov 21 '05 #1
12 1399
Perhaps I missed something but. In this example, the reference is passed
back via the constructor successfully.
//BUTTON
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim g As Guid

Dim mc As New Work(g)

Debug.WriteLine(g.ToString)
End Sub
//CLASS
Public Class Work

Private _refuid As Guid = New Guid("10001000100010001000100010001000")

Public Sub New(ByRef uid As Guid)

uid = _refuid
Debug.WriteLine(_refuid.ToString)

End Sub

Private Sub DoStuff()

End Sub

End Class
//OUTPUT

10001000-1000-1000-1000-100010001000
10001000-1000-1000-1000-100010001000

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jonas Pohlandt" <j.******************@dbit-systems.de> wrote in message
news:eo**************@TK2MSFTNGP15.phx.gbl...
Hello Group,

I used something like this in a program of mine:

public class WorkObject

private _myproperty as string

public property MyProperty as string()
get,set trivial
end property

public sub new(byval mp as string)
MyProperty = mp
end sub

end class

public class Work

private _refWorkObject as new WorkObject(String.empty)

public sub new(ByRef wo as WorkObject)
wo = _refWorkObject
DoStuff()
end sub

private sub DoStuff()
'In the real program, DoStuff() gets called after some user
interaction
'and not by the constructor like in this simplified example.
'So I cant pass wo as a parameter, I have to store it as a private
variable

_refWorkObject.MyProperty = "new value"
end sub

end class

public class main

public sub main()

dim IWantThisToChange as WorkObject
dim w as new Work(IWantThisToChange)

system.console.out.writeline(IWantThisToChange.MyP roperty) 'results in "new value"

end sub

end class
Now, all of this works fine as long as I use a reference type with public
fields / properties (workobject in this case). If I try the same thing with System.Guid instead of WorkObject, it obviously won't work. Do I really have to wrap it, or is there some funky pointer like syntax in VB.NET that I just haven't found yet.

I want something like

public class Work

private _refuid as new Guid()

public sub new(ByRef uid as Guid)
uid = _refuid
DoStuff()
end sub

private sub DoStuff()
_refuid = getdesiredvalue() 'With the variable that was passed into the work constructor taking the new value of _refuid

end sub

end class
Any help is highly appreciated.

Nov 21 '05 #2
Perhaps I missed something but. In this example, the reference is passed
back via the constructor successfully.
//BUTTON
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim g As Guid

Dim mc As New Work(g)

Debug.WriteLine(g.ToString)
End Sub
//CLASS
Public Class Work

Private _refuid As Guid = New Guid("10001000100010001000100010001000")

Public Sub New(ByRef uid As Guid)

uid = _refuid
Debug.WriteLine(_refuid.ToString)

End Sub

Private Sub DoStuff()

End Sub

End Class
//OUTPUT

10001000-1000-1000-1000-100010001000
10001000-1000-1000-1000-100010001000

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jonas Pohlandt" <j.******************@dbit-systems.de> wrote in message
news:eo**************@TK2MSFTNGP15.phx.gbl...
Hello Group,

I used something like this in a program of mine:

public class WorkObject

private _myproperty as string

public property MyProperty as string()
get,set trivial
end property

public sub new(byval mp as string)
MyProperty = mp
end sub

end class

public class Work

private _refWorkObject as new WorkObject(String.empty)

public sub new(ByRef wo as WorkObject)
wo = _refWorkObject
DoStuff()
end sub

private sub DoStuff()
'In the real program, DoStuff() gets called after some user
interaction
'and not by the constructor like in this simplified example.
'So I cant pass wo as a parameter, I have to store it as a private
variable

_refWorkObject.MyProperty = "new value"
end sub

end class

public class main

public sub main()

dim IWantThisToChange as WorkObject
dim w as new Work(IWantThisToChange)

system.console.out.writeline(IWantThisToChange.MyP roperty) 'results in "new value"

end sub

end class
Now, all of this works fine as long as I use a reference type with public
fields / properties (workobject in this case). If I try the same thing with System.Guid instead of WorkObject, it obviously won't work. Do I really have to wrap it, or is there some funky pointer like syntax in VB.NET that I just haven't found yet.

I want something like

public class Work

private _refuid as new Guid()

public sub new(ByRef uid as Guid)
uid = _refuid
DoStuff()
end sub

private sub DoStuff()
_refuid = getdesiredvalue() 'With the variable that was passed into the work constructor taking the new value of _refuid

end sub

end class
Any help is highly appreciated.

Nov 21 '05 #3
Hey Terry,

the crucial point is, I cant do it in the constructor. By "it" i mean
setting the value of the uid. Simply because I don't know it by the time the
constructor gets called.

It has to be done in the DoStuff() sub, which is called sometime after the
constructor.
In the real program, the work class is a Windows Form (or rather a subclass
of that).
The DoStuff sub is called after some user interaction. So you see my problem
is, that
I have to store the constructor paramter reference "uid" somehow, so that
dostuff can assign
it the desired value. In C/C++ I could just use a pointer variable to hold
the reference to the Guid
but I don't know how to do that in VB.NET.
Perhaps I missed something but. In this example, the reference is passed
back via the constructor successfully.

//BUTTON
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim g As Guid

Dim mc As New Work(g)

Debug.WriteLine(g.ToString)
End Sub
//CLASS
Public Class Work

Private _refuid As Guid = New Guid("10001000100010001000100010001000")

Public Sub New(ByRef uid As Guid)

uid = _refuid
Debug.WriteLine(_refuid.ToString)

End Sub

Private Sub DoStuff()

End Sub

End Class
//OUTPUT

10001000-1000-1000-1000-100010001000
10001000-1000-1000-1000-100010001000

Nov 21 '05 #4
Hey Terry,

the crucial point is, I cant do it in the constructor. By "it" i mean
setting the value of the uid. Simply because I don't know it by the time the
constructor gets called.

It has to be done in the DoStuff() sub, which is called sometime after the
constructor.
In the real program, the work class is a Windows Form (or rather a subclass
of that).
The DoStuff sub is called after some user interaction. So you see my problem
is, that
I have to store the constructor paramter reference "uid" somehow, so that
dostuff can assign
it the desired value. In C/C++ I could just use a pointer variable to hold
the reference to the Guid
but I don't know how to do that in VB.NET.
Perhaps I missed something but. In this example, the reference is passed
back via the constructor successfully.

//BUTTON
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim g As Guid

Dim mc As New Work(g)

Debug.WriteLine(g.ToString)
End Sub
//CLASS
Public Class Work

Private _refuid As Guid = New Guid("10001000100010001000100010001000")

Public Sub New(ByRef uid As Guid)

uid = _refuid
Debug.WriteLine(_refuid.ToString)

End Sub

Private Sub DoStuff()

End Sub

End Class
//OUTPUT

10001000-1000-1000-1000-100010001000
10001000-1000-1000-1000-100010001000

Nov 21 '05 #5
But all an identifier is 'IS' a reference to an object. The only difference
between a value type and a reference type with VB.NET, is that the reference
type is stored on the heap, whereas a value type is stored on the stack.

Using an identifier in VB.NET is the same as d-referencing an object pointer
in C++

Dim a,b,c as Int

a= 5
b=a
c=b

a,b,c all are references to value types stored on the stack.
Does this help.?
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jonas Pohlandt" <j.******************@dbit-systems.de> wrote in message
news:u8*************@tk2msftngp13.phx.gbl...
Hey Terry,

the crucial point is, I cant do it in the constructor. By "it" i mean
setting the value of the uid. Simply because I don't know it by the time the constructor gets called.

It has to be done in the DoStuff() sub, which is called sometime after the
constructor.
In the real program, the work class is a Windows Form (or rather a subclass of that).
The DoStuff sub is called after some user interaction. So you see my problem is, that
I have to store the constructor paramter reference "uid" somehow, so that
dostuff can assign
it the desired value. In C/C++ I could just use a pointer variable to hold
the reference to the Guid
but I don't know how to do that in VB.NET.
Perhaps I missed something but. In this example, the reference is passed
back via the constructor successfully.

//BUTTON
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim g As Guid

Dim mc As New Work(g)

Debug.WriteLine(g.ToString)
End Sub
//CLASS
Public Class Work

Private _refuid As Guid = New Guid("10001000100010001000100010001000")
Public Sub New(ByRef uid As Guid)

uid = _refuid
Debug.WriteLine(_refuid.ToString)

End Sub

Private Sub DoStuff()

End Sub

End Class
//OUTPUT

10001000-1000-1000-1000-100010001000
10001000-1000-1000-1000-100010001000


Nov 21 '05 #6
If you need to set a private member variable at any time you can set this
using a property,.

/Button

Dim mc As New Work
mc.RefUid = New Guid("00010001000100010001000100010001")
Debug.WriteLine(mc.RefUid.ToString())
//Class

Public Class Work

Private m_RefUid As New Guid

Public Sub New()

End Sub

Public Sub DoStuff(ByRef uid As Guid)
uid = RefUid
Debug.WriteLine(RefUid.ToString)
End Sub

Public Property RefUid() As Guid
Get
Return m_RefUid
End Get
Set(ByVal Value As Guid)
m_RefUid = Value
End Set
End Property
End Class
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jonas Pohlandt" <j.******************@dbit-systems.de> wrote in message
news:u8*************@tk2msftngp13.phx.gbl...
Hey Terry,

the crucial point is, I cant do it in the constructor. By "it" i mean
setting the value of the uid. Simply because I don't know it by the time the constructor gets called.

It has to be done in the DoStuff() sub, which is called sometime after the
constructor.
In the real program, the work class is a Windows Form (or rather a subclass of that).
The DoStuff sub is called after some user interaction. So you see my problem is, that
I have to store the constructor paramter reference "uid" somehow, so that
dostuff can assign
it the desired value. In C/C++ I could just use a pointer variable to hold
the reference to the Guid
but I don't know how to do that in VB.NET.
Perhaps I missed something but. In this example, the reference is passed
back via the constructor successfully.

//BUTTON
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim g As Guid

Dim mc As New Work(g)

Debug.WriteLine(g.ToString)
End Sub
//CLASS
Public Class Work

Private _refuid As Guid = New Guid("10001000100010001000100010001000")
Public Sub New(ByRef uid As Guid)

uid = _refuid
Debug.WriteLine(_refuid.ToString)

End Sub

Private Sub DoStuff()

End Sub

End Class
//OUTPUT

10001000-1000-1000-1000-100010001000
10001000-1000-1000-1000-100010001000


Nov 21 '05 #7
Hey Terry,

thanks for staying with me. ;-)

I think we're still talking about different things. Lets try this approach:
How would you implement a windows form where you pass a reference to a Guid
in the construktor and then show it modal. Upon pressing a button (and not
before that), the variable we passed in initially is assigned a specific
value, like getting the uid out of a textbox where we typed it in earlier.

Like this
dim uid as Guid
dim frm as new myFormClass(uid)

dim dr as DialogResult = frm.ShowModal()

system.console.out.write(uid) 'uid holds now the desired value.
How would you do this?

Thanks, Jonas
Nov 21 '05 #8
On 23 Sep 2004 21:00:40 GMT, Jonas Pohlandt wrote:
How would you implement a windows form where you pass a reference to a Guid
in the construktor and then show it modal. Upon pressing a button (and not
before that), the variable we passed in initially is assigned a specific
value, like getting the uid out of a textbox where we typed it in earlier.


One way would be to make a public readonly property in the dialog form and
then get that value when you close the form:

'** In the form class **
Private m_myGuid As Guid

Public ReadOnly Property MyGuid() As Guid
Get
Return m_myGuid
End Get
End Property

Private Sub Button1_Click(...) Handles Button1.Click
m_myGuid = Guid.NewGuid
End Sub
'** In the calling code

Dim uid as Guid
Dim frm As New myFormClass()

If frm.ShowDialog() = DialogResult.OK Then
uid = frm.MyGuid
End If

frm.Dispose

--
Chris

dunawayc[AT]sbcglobal_lunchmeat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #9
I think I understand you now, but your thinking is still frimly wedged in
C++ Pointers.

You cannot do this in VB.NET.

You would need to pass this variable to the function being called so that it
can be set ( as can the private member of this class ). But this does not
sound like good OOP to me, it means you are working with a variable outside
the class.


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jonas Pohlandt" <j.******************@dbit-systems.de> wrote in message
news:Xn**********************************@130.133. 1.4...
Hey Terry,

thanks for staying with me. ;-)

I think we're still talking about different things. Lets try this approach: How would you implement a windows form where you pass a reference to a Guid in the construktor and then show it modal. Upon pressing a button (and not
before that), the variable we passed in initially is assigned a specific
value, like getting the uid out of a textbox where we typed it in earlier.

Like this
dim uid as Guid
dim frm as new myFormClass(uid)

dim dr as DialogResult = frm.ShowModal()

system.console.out.write(uid) 'uid holds now the desired value.
How would you do this?

Thanks, Jonas

Nov 21 '05 #10
'** In the calling code

Dim uid as Guid
Dim frm As New myFormClass()

If frm.ShowDialog() = DialogResult.OK Then
uid = frm.MyGuid
End If

frm.Dispose

--
Chris


That's what I was looking for. I just assumed frm would have been disposed
allready by the time the line
uid = frm.MyGuid is reached. Thanks!
Nov 21 '05 #11
> I think I understand you now, but your thinking is still frimly wedged in
C++ Pointers.

You cannot do this in VB.NET.

You would need to pass this variable to the function being called so that it can be set ( as can the private member of this class ). But this does not
sound like good OOP to me, it means you are working with a variable outside the class.


You are right, the design is flawed. I ended up subclassing DialogResult and
having the subclass include the Guid.
Thanks for taking time to think about this.
Nov 21 '05 #12
Your welcome, good luck in your future .NET experience.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Jonas Pohlandt" <j.******************@dbit-systems.de> wrote in message
news:OA*************@TK2MSFTNGP11.phx.gbl...
I think I understand you now, but your thinking is still frimly wedged in C++ Pointers.

You cannot do this in VB.NET.

You would need to pass this variable to the function being called so that
it
can be set ( as can the private member of this class ). But this does
not sound like good OOP to me, it means you are working with a variable

outside
the class.


You are right, the design is flawed. I ended up subclassing DialogResult

and having the subclass include the Guid.
Thanks for taking time to think about this.

Nov 21 '05 #13

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

Similar topics

1
by: Christopher | last post by:
Hi all, I am trying to store a reference to a variable in my data providerr class but cannot save a reference to it. Can anyone help me? I would like this code to allow me to store any field...
14
by: Dave | last post by:
Hello all, After perusing the Standard, I believe it is true to say that once you insert an element into a std::list<>, its location in memory never changes. This makes a std::list<> ideal for...
12
by: Alfonso Morra | last post by:
I have the ff code for testing the concept of storing objects: #include <vector> #include <iostream> using namespace std ; class MyClass { public: MyClass(){
7
by: Bill | last post by:
Hello, Here is some code: I'm thinking that when storing an object in an ArrayList or Hashtable that it clones the object. This can be shown like so: // key is a generated hashcode for this...
0
by: Jonas Pohlandt | last post by:
Hello Group, I used something like this in a program of mine: public class WorkObject private _myproperty as string public property MyProperty as string() get,set trivial
12
by: Alex D. | last post by:
is it possible? pros and cons?
1
by: Dave Parry | last post by:
Hi, I would like to hear peoples thoughts on passing a value type by reference and then trying to store this ref in a member so it can be updated elsewhere, whereby I want the referenced value...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
1
by: Daniel Kraft | last post by:
Hi all, I tried to store a std::type_info value in my code so I didn't have to call typeid more than once when checking if a polymorphic object is of one of certain types, like this: #include...
11
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have worked with application settings in VS2005 and C# for awhile, but usually with standard types. I have been trying to store a custom container/class/type in an application setting and I have...
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: 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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.