On 16 Jun 2004 08:07:13 -0700, Krackers <krackersk@hotmail.com> wrote:
[color=blue]
> 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?
>
> cheers,
> Krackers[/color]
There is no way to return an array ByRef in Visual Basic. You can
(almost) always design code so this isn't needed. Dimension an array with
the proper Scope. Instead of returning an array ByRef, the function
manipulates an array with a higher Scope (ei outside the function) which
is then accessible outside the function.
The only situation where you might want to fiddle with array pointers is
when the array is very large, in a Class, and you need to access it from
outside the Class. This is because you can not declare a Public array in
a Class. In this situation, you can copy the pointer of the array in the
Class to a dummy array variable outside the Class. See example:
http://www.planetsourcecode.com/vb/s...52009&lngWId=1
If the array is not in a Class, or is not very large, then efficient code
can be designed such that array pointers aren't necessary.
-korejwa