LoginSignup
2
0

More than 5 years have passed since last update.

Excel-DNAからの多元配列の戻り値の取得について

Last updated at Posted at 2016-03-30

Excel-DNA側で関数を

public static object[,] DNA関数名(引数) { .. }

のように戻り値をobjectの多元配列とした場合のVBA側での受け方。

VBAでの記述

    Dim val As Variant
    val = Application.Run("DNA関数名", 引数)

のようにVariant型で受け、次元数を見て処理を分岐させる。

    d = Dimension(val)
    '0: 引数なし
    '1: n x 1配列 val(i)
    '2: n x m配列 val(i, 1), val(j, 2)
    '添え字の最少最大はLBound, UBoundで取得

Variant型の次元数は

' Variant配列の次元数を取得
Function Dimension(val As Variant) As Integer
    Dim TempData As Variant
    Dim i As Long

    On Error Resume Next
    Do While Err.Number = 0
        i = i + 1
        TempData = UBound(val, i)
    Loop
    On Error GoTo 0

    Dimension = i - 1
End Function

で取得できる。

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0