Hi,
how do you declare a default indexed property in VB.NET such that it is callable from VBScript?
I have tried this using
<DispId(0)> _
Public ReadOnly Property Item(ByVal idx As Integer) As ...
but VBScript returns the error message
Wrong number of arguments or invalid property assignment Error Code 800A01C2
This error does not occur if I expose a normal property (non-indexed) from VB.NET.
Here is a sample:
'Class1.vb:
Public Class Class1
Public ReadOnly Property Dogs() As Dogs
Get
Return New Dogs()
End Get
End Property
End Class
'Dogs.vb:
Imports System.Runtime.InteropServices
Public Class Dogs
<DispId(0)> _
Public ReadOnly Property Item(ByVal idx As Integer) As Dog
Get
Return New Dog
End Get
End Property
End Class
'Dog.vb:
Public Class Dog
Public ReadOnly Property Name() As String
Get
Return "Fido"
End Get
End Property
End Class
VBScript:
Set obj = CreateObject("FmuComTest.Class1")
MsgBox obj.Dogs.Item(0).Name ' this works
MsgBox obj.Dogs(0).Name ' error message
Accessing the default indexed property Dogs.Item(idx) causes the error message.
Regards - Frank