473,566 Members | 3,255 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 9048
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.ValueTyp e

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.ValueTyp e

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*****@singne t.com.sg> wrote in message
news:eH******** ******@TK2MSFTN GP09.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********@ema il.msn.com> wrote in message
news:ew******** **********@tk2m sftngp13.phx.gb l...
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.ValueTyp e

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.ValueTyp e

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*****@singne t.com.sg> wrote in message
news:eH******** ******@TK2MSFTN GP09.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.valuetyp e

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

public functon B1(byref arg_struct as system.valuetyp e)
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******** ******@TK2MSFTN GP09.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*****@singne t.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*****@singne t.com.sg> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. .. ok I will make an example
class1.vb :
class class1
private local_struct as system.valuetyp e

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

public functon B1(byref arg_struct as system.valuetyp e)
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******** ******@TK2MSFTN GP09.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
7661
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 create objects that reflect data gathered in web inquiries. The module has a bunch of Get/Let routines such as this pair: Private m_dYield As Double
3
3673
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 collection. So I innocently open up my class, and modify the Set sub to have BYRef instead of BYVal, and the IDE says 'Set' parameter cannot be...
7
1685
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
8861
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
1939
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
4105
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
2286
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
1760
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 After a few different approaches, I have ended up overriding the OnPaint method and using Graphics.CopyFromScreen and then painting the transparent PNG...
7
1359
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 it needed to be there.
0
7673
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7893
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7953
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6263
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5485
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
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 we have to send another system
0
926
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.