簡體   English   中英

如何將UDT數組從Excel VBA傳遞到vb.net

[英]How to pass UDT array from excel vba to vb.net

如何將用戶定義的類類型ByRef的數組從excel vba傳遞到vb.net? 我有一個類似的帖子, 這里處理傳遞雙精度數組,我嘗試對UDT使用相同的方法,但是它不起作用。 有任何想法嗎?

很抱歉,再次回答我自己的問題,該問題與我在該問題中鏈接的另一個問題非常相似,但是我能夠以與回答另一個問題幾乎相同的方式來完成它。 我只需要更改一些折射參數即可。

在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM