Re: Can you pass a Property of a User Defined Object to a Sub ByRef and Update it?
- From: "mayayana" <mayayanaXX1a@xxxxxxxxxxxxxxxx>
- Date: Wed, 11 Jan 2006 05:34:49 GMT
> While I do not claim to be an expert, I believe that I do understand
the purpose of classes, properties and functions as well as the fact
that a property is essentially a function.
>
Sorry, I didn't mean to sound condescending, but the
use of the class seemed superfluous to me, so I
wondered whether you had used them before. You're
trying to access the Dictionary and the variable from
outside the class, which defeats the purpose of the class.
It's no different than just having a global variable and
a global dictionary. In other words, the class would normally
be used because you want to design a controlled interface
for the data storage. The private members *should not*
be accessible from outside. It compromises the class's
"integrity".
So it seems like it should be something like:
[in sub]
if is isobject....
ObjClass.AddNewItem "Second", "Spiffy"
else....
ObjClass.SingleValue = "Stuff"
[in class]
Private PrivateVal
Public Sub AddNewItem(sKey, sVal)
ObjDictionary.AddItem sKey, sVal
End Sub
public property Let SingleValue(sValue)
PrivateVal = sValue
End Property
.....etc.......
That way, if you have some other reason that
you need to use a class, then the data storage
details are inside that class. You can use the Dictionary
but it doesn't risk being accessed from outside the
class.
If you don't need the class for other purposes you
can just use a globally declared dictionary and variable.
I see what you mean about the variable vs. the
dictionary, though. That's kind of a mind bender.
I guess it works that way because you're actually
passing a new variable as the return value of a property
or function, but the way it's used is different with an
object. When you do s = x.MyProperty, the value
of s becomes "Thingy".
But when you pass an object from a Property
you're passing the object pointer. If you do:
Set s = x.MyDictionary
then s is a pointer to the Dictionary.
So whether you do:
DoThing x.MyDictionary
or
Set s = x.MyDictionary
DoThing s
it's the same thing. You'll be sending the dictionary
pointer (which "from the script's point of view"
is the dictionary itself) to the sub. You can keep
changing it:
Set Dict2 = s
Set Dict3 = Dict2
DoThing Dict3
....It doesn't matter. Dict3 is still the same dictionary.
But that's not good, in this case. It's a limitation in how
objects can be used in classes.
I hope this isn't too confusing. Someone else may
have a more succinct way to describe it. I seem to
make it more complex the more I try to pin it down
in plain English, so I think I'll stop here. :)
.
- Follow-Ups:
- References:
- Prev by Date: Re: Import CSV
- Next by Date: Re: run SQL code w/ an IP connection
- Previous by thread: Re: Can you pass a Property of a User Defined Object to a Sub ByRef and Update it?
- Next by thread: Re: Can you pass a Property of a User Defined Object to a Sub ByRef and Update it?
- Index(es):
Relevant Pages
|