Pass C# array to VB6 COM function

  • Thread starter Thread starter Mullin Yu
  • Start date Start date
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
 
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).
 
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
 
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
 
yes, thanks for your info.

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

thanks a lot!
 
Back
Top