473,503 Members | 11,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

property set byref

Cc
hi,
is there a way to use byref on property set , because i would like to pass
the value into the variable byref ?
Nov 20 '05 #1
6 9035
Cc,
As Fergus suggested, I too suspect you are confusing ByRef & ByVal
parameters with Reference Types & Value Types.

Remember there are two types of Parameters (ByRef & ByVal) and there are two
types of variables (Reference Types & Value Types).

So you can have:
ByRef - Reference Type
ByRef - Value Type
ByVal - Reference Type
ByVal - Value Type

Lets look at types of variables:
When you define a Class you are defining a Reference Type. Which means that
a variable of this Class holds a reference to the object, the object itself
exists on the heap. If I assign this variable to a second variable a copy of
this reference is made and I now have two references to the same object on
the heap. There is still only one object on the heap. If you define a
Structure you are defining a Value Type. The variable itself holds the value
of the structure. If I assign this variable to a second variable a copy of
the entire structure is made. I now have two copies of the same structure.

Value Types include:
Boolean, Byte, Short, Integer, Long, Char, Single, Double, Decimal, along
with anything defined with the Structure or Enum keyword.
Value Types all derive directly or indirectly from System.ValueType

Reference Types include:
Object, and anything defined with the Class, Interface or Delegate keyword
are reference types.
Reference Types all derive from System.Object excluding types that inherit
from System.ValueType

Interface is a reference type, even if defined in a Structure. The structure
itself is a value type, however if you assign the structure to a Interface
variable, it will be Boxed, boxing places the value on the heap in a new
object (effectively making it a reference type)

Lets look at types of parameters:
Now when you define a parameter to be ByVal a copy of the variable is
passed. Remember Reference types hold a reference to the object, so passing
a Reference Type ByVal causes a copy of this reference to be passed as a
parameter, the single copy of the object itself is still on the heap. The
variable & parameter both have references to this single object. Passing a
Value Type ByVal causes a complete copy of the value to be passed as a
parameter. Now passing a Reference Type ByRef, causes a reference to the
variable to be passed, the variable has a reference to the object. Passing a
Value Type ByVal also causes a reference to the variable to be passed, the
variable has a copy of the Value.

Hope this helps
Jay
"Cc" <ko*****@singnet.com.sg> wrote in message
news:eH**************@TK2MSFTNGP09.phx.gbl...
hi,
is there a way to use byref on property set , because i would like to pass
the value into the variable byref ?

Nov 20 '05 #2
Excellent reply !

--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:ew******************@tk2msftngp13.phx.gbl...
Cc,
As Fergus suggested, I too suspect you are confusing ByRef & ByVal
parameters with Reference Types & Value Types.

Remember there are two types of Parameters (ByRef & ByVal) and there are two types of variables (Reference Types & Value Types).

So you can have:
ByRef - Reference Type
ByRef - Value Type
ByVal - Reference Type
ByVal - Value Type

Lets look at types of variables:
When you define a Class you are defining a Reference Type. Which means that a variable of this Class holds a reference to the object, the object itself exists on the heap. If I assign this variable to a second variable a copy of this reference is made and I now have two references to the same object on
the heap. There is still only one object on the heap. If you define a
Structure you are defining a Value Type. The variable itself holds the value of the structure. If I assign this variable to a second variable a copy of
the entire structure is made. I now have two copies of the same structure.

Value Types include:
Boolean, Byte, Short, Integer, Long, Char, Single, Double, Decimal, along
with anything defined with the Structure or Enum keyword.
Value Types all derive directly or indirectly from System.ValueType

Reference Types include:
Object, and anything defined with the Class, Interface or Delegate keyword
are reference types.
Reference Types all derive from System.Object excluding types that inherit
from System.ValueType

Interface is a reference type, even if defined in a Structure. The structure itself is a value type, however if you assign the structure to a Interface
variable, it will be Boxed, boxing places the value on the heap in a new
object (effectively making it a reference type)

Lets look at types of parameters:
Now when you define a parameter to be ByVal a copy of the variable is
passed. Remember Reference types hold a reference to the object, so passing a Reference Type ByVal causes a copy of this reference to be passed as a
parameter, the single copy of the object itself is still on the heap. The
variable & parameter both have references to this single object. Passing a
Value Type ByVal causes a complete copy of the value to be passed as a
parameter. Now passing a Reference Type ByRef, causes a reference to the
variable to be passed, the variable has a reference to the object. Passing a Value Type ByVal also causes a reference to the variable to be passed, the
variable has a copy of the Value.

Hope this helps
Jay
"Cc" <ko*****@singnet.com.sg> wrote in message
news:eH**************@TK2MSFTNGP09.phx.gbl...
hi,
is there a way to use byref on property set , because i would like to pass the value into the variable byref ?


Nov 20 '05 #3
Cor
Like most of your post, excellent
Nov 20 '05 #4
Cc
ok I will make an example
class1.vb :
class class1
private local_struct as system.valuetype

public function a1(byref arg_struct as system.valuetype)
if arg_struct.id =0
arg_struct.id =1
end if
end function

public functon B1(byref arg_struct as system.valuetype)
if arg_struct.id = 3
arg_struct.id = 2
end if
end function

end class
--------------------------
form1.vb
Structure Person

<VBFixedString(10)> Public ID As String

<VBFixedString(15)> Public Name As String

End Structure

private sub test()
dim testclass as new class1
dim m_person as person

m_person.id = 0
testclass.A1(m_person)

if m_person.id =1
'do something
else
m_person.id = 3
end if

testclass.B1(m_person)

msgbox(m_person.id)

end sub

----------------------------

in this example function A1& B1 are suppose to use same variable instance
that is m_person. but if I can pass by reference m_person (form1) to
local_struct (class1) that will give less coding (no need to fill in value
to the function parameter). i try to use property set for local_struct but
property set can only use byval.
I wonder why VB designer ignore such case

rgds
charles
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
Hi Cc,

What property would you like to pass ByRef and why ?

I ask because we've had a few queries about thi and it is ometimes a case of uncertainty over what ByRef is, and is for.

A bit of code may be useful.

Regards,
Fergus

Nov 20 '05 #5
"Cc" <ko*****@singnet.com.sg> schrieb
ok I will make an example
[example]
Could you please give us a working example? I tried to complete/correct the
code but without success.

in this example function A1& B1 are suppose to use same variable
instance that is m_person. but if I can pass by reference m_person
(form1) to local_struct (class1) that will give less coding (no need
to fill in value to the function parameter).
Which value? which function?
i try to use property
set for local_struct but property set can only use byval.


???
--
Armin

Nov 20 '05 #6
Cc,
in this example function A1& B1 are suppose to use same variable instance
that is m_person. Yes, we all know how to ByRef works with functions. What we want to know is
how you expect the ByRef to work with the Property Set.
but if I can pass by reference m_person (form1) to
local_struct (class1) that will give less coding (no need to fill in value
to the function parameter). i try to use property set for local_struct but
property set can only use byval. Huh? Where is this property set & what does it look like. Is it part of
Class1, Form1, Person, or some other class?

Can you continue this example and include the Property Set with ByRef so we
can see what you are attempting to do.

Remember procedures that have side effects are generally not a good idea. A
function that modifies its parameter is questionable, as a function is
intended to return a value, but wait did I mention it also modifies one of
its inputs, if I needed to modify the parameters, I would make it a Sub. A
property that only modifies its parameter is questionable. I can see
"Parent" like properties when when you set a property modifies both the
parent & child to maintain the relationship.

I strongly suspect you want (need!) the Person Structure to be a Person
Class (you know, the difference between Reference Types & Value Types, not
ByVal Parameters & ByRef Parameters).

Hope this helps
Jay

"Cc" <ko*****@singnet.com.sg> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... ok I will make an example
class1.vb :
class class1
private local_struct as system.valuetype

public function a1(byref arg_struct as system.valuetype)
if arg_struct.id =0
arg_struct.id =1
end if
end function

public functon B1(byref arg_struct as system.valuetype)
if arg_struct.id = 3
arg_struct.id = 2
end if
end function

end class
--------------------------
form1.vb
Structure Person

<VBFixedString(10)> Public ID As String

<VBFixedString(15)> Public Name As String

End Structure

private sub test()
dim testclass as new class1
dim m_person as person

m_person.id = 0
testclass.A1(m_person)

if m_person.id =1
'do something
else
m_person.id = 3
end if

testclass.B1(m_person)

msgbox(m_person.id)

end sub

----------------------------

in this example function A1& B1 are suppose to use same variable instance
that is m_person. but if I can pass by reference m_person (form1) to
local_struct (class1) that will give less coding (no need to fill in value
to the function parameter). i try to use property set for local_struct but
property set can only use byval.
I wonder why VB designer ignore such case

rgds
charles
"Fergus Cooney" <fi******@tesco.net> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
Hi Cc,

What property would you like to pass ByRef and why ?

I ask because we've had a few queries about thi and it is ometimes a

case
of uncertainty over what ByRef is, and is for.

A bit of code may be useful.

Regards,
Fergus


Nov 20 '05 #7

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

Similar topics

2
7658
by: Enigman O'Maly | last post by:
I'm still somewhat new to object style programming (as will become evident), using VBA in Excel 2000 to automate some previously manual functions. I've defined a class module so that I can...
3
3661
by: Alex Stevens | last post by:
Hi. I have a class and it exposes a property, which accepts a parameter collection object. I want the class to use the parameter object and update it. However I don't want to use a copy of the...
7
1678
by: Raymond Lewallen | last post by:
Want to know if/how to get a list of properties that are available in a class and store the properties names in an arraylist. TIA, Raymond Lewallen
9
8857
by: Stefan De Schepper | last post by:
Should I use: Private m_Name As String Public Property Name() As String Get Return m_Name End Get Set(ByVal Value As String) m_Name = Value
5
1937
by: RSH | last post by:
I havent been able to set a property from another class with out getting some sort of error. Can someone please tell me what I'm doing wrong here? Public Class Form1
1
4098
by: katzky | last post by:
My VB6 application has some properties which are set ByRef but upgrade to ByVal. How can I assure that the new code behaves the same as the old?
12
2274
by: eric.goforth | last post by:
Is there any reason to use: Private newPropertyValue As Integer Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As Integer Get Return newPropertyValue End Get End Property
3
1751
by: jarnie | last post by:
I am attempting to make a form which has alpha transparency that varies across the form, similar to the Adobe splash screens and launchy: http://www.launchy.net/images/screenshot_sheep.jpg ...
7
1355
by: Andy B | last post by:
I saw this in the set accessor of a property: Set(ByVal value As DataSet) What exactly does the stuff in the () mean? VS complained about it not being there when I took it out not knowing...
0
7207
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
7095
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
7361
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
5602
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
4693
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3183
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1523
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
749
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
403
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.