Pass C# array to VB6 COM function

M

Mullin Yu

I'm trying to pass a C# array to a VB6 COM function. There're 3 elements at
my array, but when I pass to VB6, and it displays just 2

Why? What should I do?

c#
oPrint.MergePRN(ref myTargetArray, ref strPrinter);

vb6 com
Public Function MergePRN(arrFile() As String, Printer As String) As Boolean

MsgBox UBound(arrFile)

End Function
 
K

Kolmi

This sounds very much as an index problem. You know that VBs' array indices
start at 1, while C# indices start at 0.
Try LBound(arrFile).
 
C

Chris Gallucci

While this does sound like an index problem, VB6's (aka VB Classic) array's lower bound is specified either explicitly as in...

Dim MyArray(MyLowerBound To MyUpperBound) As String

or by default as in...

Dim MyArray(MyUpperBound) As String

in which case the lower bound defaults to the value specified in the Option Base statement. If the Option Base statement is not
declared, then the default lower bounds is always 0 (zero).

HTH,

ChrisG
 
C

Chris Gallucci

The VB6 UBound() function displays the upper bound index of an array not the number of elements. An array that is zero-based with
three elements will have an upper bound index of 2, i.e.,

?UBound(MyArray)
2

HTH,

ChrisG
 
M

Mullin Yu

yes, thanks for your info.

i changed the vb array starting from 0, instead of 1, then it works now.

thanks a lot!
 

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