Originally Posted by
hic24
But doesn't the same occur in each subsequent recursive call? So each call is just adding the next call's return value to zero.
Each function call starts with the zero value of this function (in this case Empty, which will be converted to 0). Summation occurs by passing arguments to a function. When you call a function recursively, you still pass arguments. In the line
you pass the calculated value of the function for this moment of computation and the array of successive values. So you passed two arguments that will eventually be summed up.
For you, I was analyzing such a sheet function
The test showed that in this code snippet:
should be changed to
Perhaps this fragment needs to be further developed to handle two- and multidimensional arrays.
In order to understand in depth the operation of the function, I propose to analyze it in step mode.
1. Insert a breakpoint in the lines: - For i = 0 To UBound(args)
- (after Case "Variant()") n = args(i)
- (after Case Else) MYSUM = MYSUM + args(i) and
- End Function
2. In the Watches window, add the watches you want to watch: MYSUM, args, and n
3. Now insert i.n.t.o any cell as a sheet function (i.n.t.o = into)
4. Go through the execution in steps (F8) and observe the watches values.
Do this patiently until the end of the function. I think then you will understand how it works.
Artik
Bookmarks