title: Passing arrays from VBA to VB.NET
body: <p>I am working on a vb.net COM interop to work in Microsoft Excel and I am having trouble passing arrays from vb to vb.net. I have a <code>PointPairs</code> property in the vb.net code that I need to set from vb and I am having trouble passing the 2 dimensional array. I have tried both setting the property explicitly with a 2D array as well as passing two 1D arrays into a Sub to try and set the property in vb.net, but nothing I have tried seems to work.</p>
  
  <p>vb.net code:</p>
  
  <pre><code>Public Property PointPairs() As Double(,)
     Get
       ...
       Return array
     End Get
     Set(ByVal Value(,) As Double)
       ...
     End Set
  End Property
  
  Public Sub SetPointPairs(ByRef spline As Spline, ByRef xValues() As Double, _
                                ByRef yValues() As Double)
     Dim Value(,) As Double
     ReDim Value(1, UBound(xValues, 1))
  
     For i As Integer = 0 To UBound(xValues, 1)
         Value(0, i) = xValues(i)
         Value(1, i) = yValues(i)
     Next
  
     spline.PointPairs = Value
  End Sub
  </code></pre>
  
  <p>vb code:</p>
  
  <pre><code>Dim spline1 As New Spline
  Dim points(), xValues(), yValues() As Double
  'read input from excel cells into points() array/add x and y values to respective arrays
  
  spline1.PointPairs = points 'first method (doesn't work)
  Call SetPointPairs(spline1, xValues, yValues)  'second method (doesn't work)
  </code></pre>
  
  <p>Everything is being exported correctly by vb.net and the properties/subs/functions are visible in the Object Browser in vba, however when I try to pass arrays in these two approaches I get error messages <code>Function or interfaces markes as restricted, or the function uses an automation type not supported in Visual Basic</code> or <code>Sub or Function not defined</code>. I have also tried using <code>&lt;MarshalAs()&gt;</code> but I have never used it before and can't find much documentation on how to use it for passing arrays between vb and vb.net.</p>
  
  <p>Thanks in advance for any suggestions or solutions</p>