Accessing .NET Collection in VB6

放肆的年华 提交于 2019-12-04 18:47:19

Microsoft.VisualBasic.Collection is compatible member-wise, but it's not the same type.

Why not just return an array? Of strings, or of your COM-visible .NET classes?
Or create an indexed property?


Having that said, why not return IList in the first place? IList is COM-visible.
This works:

<Microsoft.VisualBasic.ComClass()> _
Public Class Class1

    Public Function Test() As IList
        Dim l() As String = New String() {"abc", "def", "42"}
        Return l
    End Function

End Class

 

Private Sub Command1_Click()
  Dim c As New ClassLibrary1.Class1

  MsgBox c.Test(2)
End Sub

You can return object's array its more light with "Microsoft.VisualBasic.Collection" i never work well the end is the same you have convert from type to type, something how that

Dim a As MyDotNet.MyCOMClass
dim ptr as variant
Set a = New MyDotNet.MyCOMClass
Dim c As Collection
ptr = a.TestMe()
Set c = ptr

if that not work return array of objects. remember you have enable in project settings

application -> assembly information -> Make assembly COM-Visible (true) and compile -> Register for COM interop (true)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!