![](/img/trans.png)
[英]Switch from VBA to VB.net - change Array of Arrays (variant) to?
[英]How to pass UDT array from excel vba to vb.net
很抱歉,再次回答我自己的問題,該問題與我在該問題中鏈接的另一個問題非常相似,但是我能夠以與回答另一個問題幾乎相同的方式來完成它。 我只需要更改一些折射參數即可。
在vb.net代碼中,我將參數作為對象,獲取該對象的類型(它識別為object()數組),然后使用vb.net中的以下函數將該對象數組直接轉換為所需的類數組
Friend Function ComObjectArrayToPointArray(ByVal comObject As Object) As Point()
Dim thisType As Type = comObject.GetType
Dim fibType As Type = Type.GetType("System.Object[]")
Dim fibArray(0) As Point
If thisType Is fibType Then
Dim args(0) As Object
Dim numEntries As Integer = CInt(thisType.InvokeMember("Length", BindingFlags.GetProperty, _
Nothing, comObject, Nothing))
ReDim fibArray(numEntries - 1)
For j As Integer = 0 To numEntries - 1
args(0) = j
fibArray(j) = DirectCast((thisType.InvokeMember("GetValue", BindingFlags.InvokeMethod, _
Nothing, comObject, args)), Point)
Next
End If
Return fibArray
End Function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.