UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
> Problem Trying To Make A Property Of A Class The Default.    
 
   
MayasPapaS
post Nov 7 2018, 08:13 PM
Post#1



Posts: 3
Joined: 6-October 18



Caveat: As this is my first post ever, on any forum, I would also appreciate any input regarding the post itself as well!

In a Class Module, clsCollection (a wrapper of the VBA Collection object), a code snippet of which appears below,
I wanted to cause the 'Item' property to be set as the default property/procedure so that I can use the oCollection(Index) syntax instead of oCollection.Item(Index) syntax.
I also wanted the ability to enumerate the items in the collection using the For Each Object In oCollection … Next construct.
According to the Wrox publication "Access 2007 VBA: Programmer's Reference", both of these tasks are doable using the code below, which I copied from the .txt file that I imported into my project.
I also found the same kind of thing in a Wiki article Wiki.Classes.Collection.

End Result:
The default property Attribute doesn't work, but the enumeration one does!
It is worth noting that if I export the file again, after having imported the code below, the NewEnum() function shows it's attribute but the Item() property does not!

Code snippet:
Private mColl As Collection

Public Property Get Item(vIndex As Variant) As Variant
Attribute Item.VB_UserMemId = 0 'Set as default property?? -- Doesn't work!
Set Item = mColl(vIndex)
End Property

Public Function NewEnum() As Iunknown
Attribute NewEnum.VB_UserMemId = -4 'This one works; allowing a For … Each construct!!
Set NewEnum = mColl.[_NewEnum]
End Function

Thanks!!
Go to the top of the page
 

Posts in this topic



Custom Search


RSSSearch   Top   Lo-Fi    24th January 2020 - 06:00 AM