Re: Can you pass a Property of a User Defined Object to a Sub ByRef and Update it?



The property is part of the class. You're
treating it as just a plain variable, but it's
really a function. You might want to read up on
classes, functions and properties, and the
possible reasons to use them.

The main point of a class is
to "encapsulate" reusable code in a
self-contained scope. In other words, the class
allows you to keep code separate from the
main body of the script and only present access
to it in ways that you define through public
properties and functions.

If you want full "global" access to the variable
then there's no reason to have a class in the first
place.
--
mayayanaXX1a@xxxxxxxxxxxxxxxx
(Remove Xs for return email.)
Shadow Lynx <shdwlynxjunk@xxxxxxxxx> wrote in message
news:1136882952.731491.246530@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> When passing a property of a user defined object into a sub, even with
> ByRef specified, it does NOT apply changes made in the sub.
>
> For instance, in the as-simple-as-I-can-make-it code below, I expect
> that the variable y, local to the sub DoThing, is a pointer to
> x.MyProperty. So why does the page output "Thingy", which is the value
> that x.MyProperty is initially set to, rather than "Stuff"? Without
> being able to modify the property of a custom object, many of the
> functions I have planned will be, for lack of a better word, worthless.
> I realize that I can return a single value with a function, but I need
> to be able to, for example, set values for multiple properties of a
> custom object.
>
> Dim x: Set x = New MyUserType
> x.MyProperty = "Thingy"
> DoThing x.MyProperty
> Response.Write(x.MyProperty)
> Set x = Nothing
>
> Sub DoThing(ByRef y)
> y = "Stuff"
> End Sub
>
> Class MyUserType
> Private varMyProperty
> Public Property Let MyProperty(value)
> varMyProperty = value
> End Property
> Public Property Get MyProperty
> MyProperty = varMyProperty
> End Property
> End Class
>


.



Relevant Pages

  • Re: reflecting on custom object
    ... The custom object is a Web Service Client Proxy ... |> Public Sub New ... |> Private _firstname As String ... |> Public Property FirstNameAs String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: reflecting on custom object
    ... The custom object is a Web Service Client Proxy class ... > Public Sub New ... > Private _firstname As String ... > Public Property FirstNameAs String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: DC another Problem
    ... > Private PointsDraw As ClassPoints ... > Private Sub Command1_Click ... > Dim p As Classpoint ... > Public Property Let X ...
    (microsoft.public.vb.winapi.graphics)
  • Re: Rearrange desktop
    ... Dim m_htTitlebar ' used in geom calcs ... Const GWL_STYLE = ... Sub RepositionDesktopIcons() ... Public Property Let Mask ...
    (microsoft.public.scripting.vbscript)
  • Re: DC another Problem
    ... >>Private PointsDraw As ClassPoints ... >>End Sub ... >>Dim p As Classpoint ... >>Public Property Let X ...
    (microsoft.public.vb.winapi.graphics)

Loading