Passing Collection from .net to VB6

J

Jacques Wentworth

Hi

I'm trying to pass a collection from a .NET DLL to a VB6 app. I get a
error 13 (type mismatch) when I do so. I passed back a boolean variable
without any problems, but when I try the collection I get the error.

As you can see the function does not do anything at the moment, so it
must be some issue passing the collection.

Thanks

..NET
Public Interface IHSTCradleData
'Function Fetch(ByVal intFacility As Integer, _
' ByVal intMonth As Integer, _
' ByVal intYear As Integer) As Boolean
Function Fetch(ByVal intFacility As Integer, _
ByVal intMonth As Integer, _
ByVal intYear As Integer) _
As Microsoft.VisualBasic.Collection
End Interface

Public Class HSTCradleData
Implements IHSTCradleData

Function Fetch(ByVal intFacility As Integer, _
ByVal intMonth As Integer, _
ByVal intYear As Integer) _
As Microsoft.VisualBasic.Collection _
Implements IHSTCradleData.Fetch

Return New Collection
End Function
End Class


VB6
Dim x As New HSTCradleData.HSTCradleData
Dim c As Collection
Set c = x.Fetch(txtFacCode.Text, txtMonth.Text, txtYear.Text)
MsgBox c.Count
 
K

Ken Tucker [MVP]

Hi,

The vb.net collection is not the same as the vb6 collection.
Microsoft.VisualBasic.Collection is the same as the vb6 collection



Ken

------------------------------

Hi

I'm trying to pass a collection from a .NET DLL to a VB6 app. I get a
error 13 (type mismatch) when I do so. I passed back a boolean variable
without any problems, but when I try the collection I get the error.

As you can see the function does not do anything at the moment, so it
must be some issue passing the collection.

Thanks

..NET
Public Interface IHSTCradleData
'Function Fetch(ByVal intFacility As Integer, _
' ByVal intMonth As Integer, _
' ByVal intYear As Integer) As Boolean
Function Fetch(ByVal intFacility As Integer, _
ByVal intMonth As Integer, _
ByVal intYear As Integer) _
As Microsoft.VisualBasic.Collection
End Interface

Public Class HSTCradleData
Implements IHSTCradleData

Function Fetch(ByVal intFacility As Integer, _
ByVal intMonth As Integer, _
ByVal intYear As Integer) _
As Microsoft.VisualBasic.Collection _
Implements IHSTCradleData.Fetch

Return New Collection
End Function
End Class


VB6
Dim x As New HSTCradleData.HSTCradleData
Dim c As Collection
Set c = x.Fetch(txtFacCode.Text, txtMonth.Text, txtYear.Text)
MsgBox c.Count
 
A

Andrew D. Newbould

Jacques Wentworth said:
Hi

I'm trying to pass a collection from a .NET DLL to a VB6 app. I get a
error 13 (type mismatch) when I do so. I passed back a boolean variable
without any problems, but when I try the collection I get the error.

As you can see the function does not do anything at the moment, so it
must be some issue passing the collection.

Thanks

.NET
Public Interface IHSTCradleData
'Function Fetch(ByVal intFacility As Integer, _
' ByVal intMonth As Integer, _
' ByVal intYear As Integer) As Boolean
Function Fetch(ByVal intFacility As Integer, _
ByVal intMonth As Integer, _
ByVal intYear As Integer) _
As Microsoft.VisualBasic.Collection
End Interface

Public Class HSTCradleData
Implements IHSTCradleData

Function Fetch(ByVal intFacility As Integer, _
ByVal intMonth As Integer, _
ByVal intYear As Integer) _
As Microsoft.VisualBasic.Collection _
Implements IHSTCradleData.Fetch

Return New Collection
End Function
End Class


VB6
Dim x As New HSTCradleData.HSTCradleData
Dim c As Collection
Set c = x.Fetch(txtFacCode.Text, txtMonth.Text, txtYear.Text)
MsgBox c.Count

Not sure if this will help but:-

1. Your Fetch method takes Integer parameters and you are passing
string data. Use CLng function in VB6 to cast the string (ie: Integers
in .Net are Longs in VB6).

2. Your Fetch method declares the parameters as ByVal when the default
in VB6 is ByRef and again you are NOT casting the strings (ie: add ByVal
to the VB6 call).

Kind Regards,
 
M

Michael Cole

Did u find the solution i am getting the same error i cant passn the
collection from .net to vb can u give me ur solution

I think you may have a problem with your keyboard. It seems to be dropping
letters and punctuation marks.
 

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