PDA

View Full Version : default property of a class



dlh
09-04-2008, 12:20 PM
I'm new to creating my own classes. I've learned a lot from Chip Pearson's site: http://www.cpearson.com/excel/Classes.aspx and from this post here: http://vbaexpress.com/forum/showthread.php?t=18495.

I've read in a couple places that there can only be one default property of a class, but they seem to mean that there can be only one default procedure. A property can be associated with both a Let and a Get procedure, so is there a way of getting a property to be both a read-default and a write-default for a class?

Bob Phillips
09-04-2008, 02:27 PM
No, the property is default, and both the read and write attributes of that property will inherit that default, whether you separately classify them in the class or not.

dlh
09-04-2008, 02:53 PM
Thank you very much, xld. Upon reexamination, my confusion arose because I had a problem with initialization at the same time as I tried assigning the default property. I thought Set would work as a constructor. Apparently this doesn't work:


Dim MyObj as MyClass
Set MyObj = "string to put in MyObj's default property"

But this does work:


Dim MyObj as MyClass
Set MyObj = New MyClass
MyObj = "string to put in MyObj's default property"