Passing array to a function and returned another array

jxb

Board Regular
Joined
Apr 19, 2007
Messages
172
Office Version
  1. 2010
Platform
  1. Windows
To all,

I am testing passing an array from a sub to a function which then returns an array.I am having trouble with the indices. The test below doesn't do anything clever. I am only testing passing array()

Thanks
Regards
JXB

'----------------------------------------------
Sub TestingArray()

Dim myvalues()
Dim testarray()
myvalues={0.,0.,0.,0.} ' initialise array
testarray={0.,0.,0.,0.} ' initialise array

'Pass the array testarray() to function ReturnedArray()
'the function ReturnedArray() returns a new array
'which is allocated to array myvalues()

myvalues = ReturnedArray(testarray)

End Sub

Function ReturnedArray(ByRef InputArray() As Object)
Dim myarray() as Double = {10,20,30,40}
ReturnedArray=myarray()
End Function
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi Adnrew

Because I originally defined my function as follows

Public Function DoMyArray(ByRef InputArray() As Variant)

and the "compiler" (i.e. the 1/3 party software) I am using returned message about VARIAN no longer being supported and one should use Object!

Thanks for the link
I am now testing on of the test on the provided link
and I keep getting an error
number of indices is less than the number of dimensions of the indexed array
at the line where the function LoadNumbers() is allocated the array

LoadNumbers = ResultArray()

This is the same problem that prompted the original query

Thanks

Regards

JXB
 
Upvote 0
What language are you actually using? Presumably not VBA.
 
Upvote 0
I am programming in vb but the "final" cut is run in another software i.e. not Excel
I did all the programming in Excel and it did the job (rather well). I know that there are specific keywords not recognised such as 'debug.print' but that's very easy to fix/replaced
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,399
Members
448,958
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top