VB.NET equivalent of VB6 Attribute Item.VB_UserMemId = 0

I updated the class from VB6 to VB.NET, which will be used in Excel through COM.

In VB6, I have a property defined in the MyScalars class as follows:

 Public Property Get Item(vntIndexKey As Variant) As MyScalar Attribute Item.VB_UserMemId = 0 Set Item = mCol(vntIndexKey) ... End Property 

This is similar to the fact that in Excel VBA I can access this property without specifying it (like the default property):

 Dim oOut As Object Set oOut = MyScalars(Range("E10").Value) 

Is there an equivalent attribute in VB.NET that does this? I tried the following, but it gives an error in VBA:

 Default Public ReadOnly Property Item(ByVal vntIndexKey As String) As MyScalar Get If mCol.ContainsKey(vntIndexKey) Then Item = mCol.Item(vntIndexKey) End If ... End Property 
+7
excel-vba excel vb6
source share
1 answer

Govert's answer is correct. All members of the COM IDispatch interface are automatically marked with the DISPID icon when converting from .NET to COM. The one exception to this automatic process is the value 0, which is reserved for the default member of the class. if you do not set DISPID , the default member of .NET classes when porting to COM is the ::ToString method. In your example:

 < DispId(0) > _ Public ReadOnly Property Item(ByVal vntIndexKey As String) As MyScalar End Property 
+2
source share

All Articles