Recursion Question

1. Senior Member
Join Date
Dec 1969
Posts
115

## Recursion Question

For some reason the array arrIndex does not get passed back up through the stack. Can someone explain why, or give me an idea how to do this quicker...<BR><BR>function Get2DArrayIndex(byref myarray, myval, mydepth, myindex)<BR> for each thing in myarray<BR> if IsArray(thing) then<BR> arrIndex=get2DArrayIndex(thing, myval, mydepth+1, myindex)<BR> if not IsEmpty(arrIndex) then Exit For<BR> else<BR> if thing=myval then<BR> arrIndex=array(mydepth, myindex)<BR> Exit For<BR> end if<BR> myindex=myindex+1<BR> end if<BR> next<BR>&#039; if IsEmpty(arrIndex) then<BR>&#039; arrIndex=array(mydepth, myindex)<BR>&#039; end if<BR> GetArrayIndex=arrIndex<BR>end function<BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## Use OPTION EXPLICIT...

...and you&#039;d find this kind of stuff.<BR><BR>function Get[hl="yellow"]2D[/hl]ArrayIndex( .... )<BR> ... <BR> GetArrayIndex=arrIndex<BR>end function<BR><BR>Also, you have a major goof: You didn&#039;t make THING or ARRINDEX into local variables in the recursive function!<BR><BR>You *NEED* to do<BR><BR>function Get2DArrayIndex( .... )<BR> Dim thing, arrIndex<BR> ...<BR><BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
6,476

## RE: Recursion Question

Out of curriosity<BR>myarray &#039;this is an actual array correct?<BR>Then you try to itterate through that array like this<BR><BR>for each thing in myarray <BR>so you want to get each element of the array correct?<BR><BR>Then for each element you use this "If" statement below.<BR>if IsArray(thing) then<BR><BR>Is each "Thing" thats inside that myarray array, truely an array?<BR>Not some other datatype like int, string, bol etc...?<BR><BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
6,476

## Pardon me while I

take another pill and head straight to bed.<BR>

5. Senior Member
Join Date
Dec 1969
Posts
96,118

## I didn't understand the purpose...

...of the code, either, Russell.<BR><BR>I just looked for the coding errors.<BR><BR>The more I look at it, the stranger it is. It&#039;s not a 2D array, at all.<BR><BR>It&#039;s an array *OF* arrays. And each of the inner arrays might also be an array OF arrays. And...<BR><BR>But I sure don&#039;t get what the goal is.<BR><BR><BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
6,476

## RE: I didn't understand the purpose...

Ahh IC or correctly I should say, I didnt see...<BR>I hate working with functions so dont pick up on much about them...<BR><BR>I like subs more.<BR>Im a big eater & subs are easier to digest...<BR>hmmm<BR>Blue pill, or red ;o)

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Besides...

...subs can come up in the bathtub and peer around with their periscopes.<BR><BR>Especially the yellow ones.<BR><BR>[My son, at age 8 thru maybe 13, must have watched "Yellow Submarine" a hundred times. One of the first videotapes we ever recorded (long before it came out commercially) and he wore out a couple of copies. I won&#039;t bother to tell you what he&#039;s like today, at age 33.]<BR><BR>

8. Senior Member
Join Date
Dec 1969
Posts
6,476

## RE: Besides...

I still like watching that movie now and then...<BR>But that requires the "Yellow pill"<BR>hehee

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•