【发布时间】:2013-07-07 06:55:54
【问题描述】:
我正在开发一个在 Microsoft Excel 中工作的 vb.net COM 互操作,我在将数组从 vb 传递到 vb.net 时遇到问题。我在 vb.net 代码中有一个 PointPairs 属性,我需要从 vb 设置它,但我无法传递二维数组。我已经尝试使用 2D 数组显式设置属性以及将两个 1D 数组传递到 Sub 以尝试在 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 之间传递数组的文档。
提前感谢任何建议或解决方案
【问题讨论】:
标签: excel vba vb.net com excel-interop