Rick,
The array would be held in a class, it's scope is module level. the
function is a function of the class and I want it to return a
reference to the module level array.
the code looks something like this:
'<class arrayHolder - Start>
private mArray()
public function rtnArray() as variant()
'code to do some formating to the array
rtnArray = mArray
end function
'<class arrayHolder - end>
I then want any changes outside the class 'arrayHolder' to affect the
array in arrayHolder (mArray). To make the 'mArray' public scope means
I wouldn't be able to run code before it was accessed because any
class would be able to access it directly. If returning a variable
from a function is by value only then I'll have to make the array
public or use a collection instead of an array (collections always
pass by reference since they are an object) but this would mean a fair
amount of code rewriting. If there is a way of making the return
variable of the function by reference it would save me a lot of time.
cheers,
Krackers
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message news:<Zu********************@comcast.com>...
How do you write a function which returns a reference to an array. I
can only get a function to return a copy of the array itself. I've had
a look at some other threads in this group an the return value of a
function acts like 'by Val' returning the value only (except for
objects) can you make it return a reference instead?
Do you mean you want your function to create an array out of thin air
and then give you access to it from outside of the function? You can't
do that; things declared inside of a function or sub are local to that
procedure. Besides, if you could do that, what would that mean the next
time the function was called? Anyway, you could declare an array in the
(General)(Declarations) section of a form (making it have form-wide
scope) or as Public in a BAS module (making it have project wide scope)
and then stuff values into it from within your function (and maybe ReDim
it if necessary). Other routines could then pick up the values by simply
referencing the "global" array variable directly.
Rick - MVP