Hello Kyle/mikerickson,
Thanks for answer. I've tried both solutions and I've been able to adapt mike's solution but not Kyle´s solution.
For Kyle's solution I have issues assigning the values to the arrays within the function and for mike's solution, it seems to work
fine, but the numbers are stored as string, I'm not sure why. I'm modified I little bit your codes since the input of the function is
a variant array of n x m dimensions.
This is what I've done:
Kyle´s solution: (I get wrong number of dimensions inside the function)
Sub test_Kyle()
Dim arr, myArray1, myArray2
a = [{1,2,3;4,2,1;10,2,7}]
arr = testArr(a)
myArray1 = arr(0)
myArray2 = arr(1)
End Sub
Function testArr(MyArr As Variant) As Variant
Dim arr(1, 1)
For i = 1 To 3
For j = 1 To 2
arr(0)(i, j) = MyArr(i, j) + 1
arr(1)(i, j) = MyArr(i, j) + 2
Next j
Next i
testArr = arr
End Function
mikerickson´s solution:
Sub test_mikerickson()
Dim firstReturn As Variant
Dim secondReturn As Variant
a = [{1,7.3,3;4,4,1;10,0.9,7}]
firstReturn = myFtn(a, secondReturn)
'MsgBox Join(firstReturn) & vbCr & Join(secondReturn)
End Sub
Function myFtn(MyArray As Variant, Optional ByRef secondArray As Variant) As Variant
Dim Result1(1 To 3, 1 To 2) As String
Dim Result2(1 To 3, 1 To 2) As String
Dim i As Long
For i = 1 To 3
For j = 1 To 2
Result1(i, j) = MyArray(i, j) + 1
Result2(i, j) = MyArray(i, j) + 2
Next j
Next i
myFtn = Result1
secondArray = Result2
End Function
Thanks again for the help
Bookmarks