Hi Caspar,
Your array arguments must be of type Object(,) or Double(,). There is
also support for one-dimensional arrays Object() and Double(), with
some detection to deal with both rows and columns. To limit confusion,
I would probably suggest you always use the two-dimensional arrays,
and deal with the sizes of both dimensions yourself.
From a 2D array you can retrieve the dimensions with
myArray.GetLength(0) and myArray.GetLength(1).
There is also the notion of allowing a reference to be passed to your
function, instead of the dereferenced values as in the examples below.
Getting the reference is closer to the VBA concept of a Range argument
and is sometimes useful. But I won't elaborate on that now.
Note that string arrays are not currently supported – you have to do
the conversion to strings yourself. I think they will be some day.
I paste a .dna file below that defines some functions you can try out.
Please post back if you have more specific questions.
Regards,
Govert
<DnaLibrary Name="ExcelDna TestVBArrays">
<![CDATA[
Public Module Test
Function AddThemAll(values(,) As Double) as Double
Dim i As Integer
Dim j As Integer
For j = 0 To values.GetLength(1) - 1
For i = 0 To values.GetLength(0) - 1
AddThemAll = AddThemAll + values(i,j)
Next i
Next j
End Function
Function ConcatThem(values(,) As Object) as String
Dim i As Integer
Dim j As Integer
ConcatThem = ""
For j = 0 To values.GetLength(1) - 1
For i = 0 To values.GetLength(0) - 1
ConcatThem = ConcatThem & values(i,j).ToString()
Next i
Next j
End Function
Function ReturnAnArray() as Object(,)
Dim result(2,3) as Object
result(0,0) = 123.456
result(0,1) = "asd"
result(0,2) = DateTime.Now ' Will look like a number
result(1,0) = ExcelError.ExcelErrorValue
result(1,1) = Nothing ' null is converted to 0 by Excel
result(1,2) = "" ' Looks empty but is a string
ReturnAnArray = result
End Function
End Module
]]>
</DnaLibrary>