View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default keep recursion result (a dynamic array) without using global variable

you can only redim the last dimension in you want to preserve the results.

If you want to accumulate the results from many separate calls, then a
global variable/array seems like a good choice.

The alternative would be to pass the array as an argument, but then all the
calls would have to come from a the source of the array.

--
Regards,
Tom Ogilvy

"lvcha.gouqizi" wrote in message
oups.com...
Hi there,

I write a recursive subroutine which can be called by several macros
from different modules. I want to keep a dynamic array as a result of
this recursive code. I define an array as a global variant like:
Dim result() as Variant
Redim result(1 to 5, 1 to 20)

And whenever the recursion gets a correct answer, I add it to the
array. The recursion works well when called by its own module. But when
code from other module calls it, I am confused about how to deal with
the global array? Is there any way to keep recursion results without
using global variable?

Can I use a dynamic array parameter and an integer paramter to save its
increasing size like the following?

sub myrecursion(dynArr() as variant, dynArrLen as integer)

Thanks.
lvcha