Problem passing Collection from VB.Net to VB6

H

holysmokes99

I have run the VB.Net upgrade wizard to get a vb6 project up to VB.Net
1.1. This is a class library that is referenced by another VB6 app. I
have exposed it to for COM access. The problem is that the collection
object that is being passed from VB.Net to VB6 is giving me a "type
mismatch" error when assigned to a collection variable in vb6. The
collection in VB.Net is Microsoft.VisualBasic.Collection, so I do not
see why this is causing any trouble at all. Here is some example code
that causes the problem mentioned:

----------------------------
VB.Net Class:
----------------------------
<System.Runtime.InteropServices.ProgId("Marcus_Test.Class1"),
ComClass(Class1.ClassId, Class1.InterfaceId, Class1.EventsId)> _
Public Class Class1

#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String =
"7E2FF7F3-8546-4987-AF5A-4A725211B807"
Public Const InterfaceId As String =
"7B84FBBA-4241-44fc-AD13-C988D75E5B5C"
Public Const EventsId As String =
"24672225-C20D-4020-ACA9-FDF5E494C5BC"
#End Region

Public Function GetCollection() As Microsoft.VisualBasic.Collection
Dim c As New Collection
c.Add("Hello")
c.Add("there")
c.Add("you")
Return c
End Function

End Class


------------------------------
VB6 Code that references it (with proper reference added in
'references' of course)
------------------------------
Private Sub Command1_Click()
Dim c As Collection
Dim myClass As New ClassLibrary1.Class1
Set c = myClass.GetCollection 'THIS LINES CAUSES "TYPE MISMATCH"
ERROR
End Sub


Any thoughts on why this error is occuring? How can I pass a
Microsoft.VisualBasic.Collection from .Net to vb6?

Thanks for any suggestions.

Marcus
 
C

Cor Ligthert [MVP]

Holysmoke,

The only class that most regulars or others find it a pity that it is in the
VB namespace and not in the compatilbe namespace (which is temporaly) is the
vb.collection. It gives you only trouble.

Try to change it as soon as possible for a Net List or Collection class as
soon as possible.

As most things which have synonyms it is now almost impossible to find on
MSDN. You have first to strugle through things as foxpro etc. But try it.
Keywords to search are Ilist ICollection "Collection Class" "List Class"
"Generic list"

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top