我正在使用vb.net COM互操作在Microsoft Excel中工作,而且我無法將數組從vb傳遞到vb.net。我在vb.net代碼中有一個PointPairs
屬性,我需要從vb設置,並且無法傳遞2維數組。我已經嘗試使用2D數組顯式設置屬性,並將兩個1D數組傳遞給Sub以嘗試在vb.net中設置屬性,但我沒有試過似乎沒有任何效果。將數組從VBA傳遞到VB.NET
vb.net代碼:
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
VB代碼:
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)
一切正在由vb.net正確導出和屬性/潛艇/功能是在VBA對象瀏覽器可見,但是當我嘗試在這兩種方法中傳遞數組時,我收到錯誤消息Function or interfaces markes as restricted, or the function uses an automation type not supported in Visual Basic
或Sub or Function not defined
。我也嘗試使用<MarshalAs()>
,但我從來沒有使用過它,無法找到關於如何使用它在vb和vb.net之間傳遞數組的很多文檔。
預先感謝任何建議或解決方案