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



> 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. :)



.



Relevant Pages

  • Re: I would like to display....
    ... Im not sure it serve my purpose. ... Members who are logged in to my site i whant to display on a list. ... >> Regards Mikael ... > sub session_onstart ...
    (microsoft.public.inetserver.asp.general)
  • Re: Claiming a loan as a Sole Trader?
    ... business or private depending on the purpose of the next trip, ... none of its cost can be claimed. ...
    (uk.business.accountancy)
  • Re: Batch processing of JPEG images
    ... 1hh91t6.1lhznk2c9b3kxN%usenet@xxxxxxxxxxxxxxxxxxxxxxxxxxx, "James Taylor" ... reduce down to sub 50K file size for the purpose of sending by email ... What is my best option for batch scaling ...
    (uk.comp.sys.mac)
  • Re: Combobox in Menu Bar Event code
    ... What is the purpose of the application? ... Sub AddMenuItem() ... Dim objCommandBarComboBox As Office.CommandBarComboBox ... Jean-Guy Marcil - Word MVP ...
    (microsoft.public.word.vba.general)
  • Re: Private methods - only available to oneself?
    ... what's the purpose of 'protected' or 'private'?" ... Or look at it this way: It makes it "more difficult" to access private ... def foo_one ... def bar ...
    (comp.lang.ruby)