finding arrays within arrays of arrays

# Thread: finding arrays within arrays of arrays

1. Senior Member
Join Date
Dec 1969
Posts
115

## finding arrays within arrays of arrays

If I have an array thus:<BR><BR>myarray(0)=array(0, 1)<BR>myarray(1)=array(10, 11)<BR>myarray(2)=array(20, 21)<BR>myarray(3)=array(30, 31)<BR>myarray(4)=array(40, 41)<BR>myarray(5)=array(50, 51)<BR><BR>and I want to find out if the following arrays are in myarray:<BR>array1=array(30, 31)<BR>array2=array(60, 51)<BR><BR>I started with this idea:<BR><BR>function ArrayIsInArray(MyFirstArray, MySecondArray)<BR>&#039;Determine if MyFirstArray is in MySecondArray<BR> IsIn=false<BR> for each thing in MySecondArray<BR> counter=0<BR> for each piece in thing<BR> if IsArray(piece) then<BR> IsIn=ArrayIsInArray(MyFirstArray, piece)<BR> else<BR> if piece=MyFirstArray(counter) then <BR> IsIn=true<BR> else<BR> IsIn=false<BR> end if<BR> counter=counter+1<BR> end if<BR> next<BR> if IsIn then Exit For<BR> Next<BR> ArrayIsInArray=IsIn<BR>end function<BR><BR><BR>But this gives a false positive because the value 51 turns IsIn true when really it shouldn&#039;t.<BR><BR>So how do I get around this problem?<BR>

2. Senior Member
Join Date
Dec 1969
Posts
16,931

## RE: finding arrays within arrays of arrays

I am REALLY confused. What&#039;s populating those arrays - a database? Sounds like a database-y kind of situation. If so, can&#039;t you do this at the database end? It&#039;s going to get disgustingly recursive otherwise.<BR><BR>Craig.

3. Senior Member
Join Date
Dec 1969
Posts
115

## RE: finding arrays within arrays of arrays

yeah, I wish I was good enough at SQL to do all this in the DB, but I don&#039;t even know where to start with that...

4. Senior Member
Join Date
Dec 1969
Posts
115

## Ha! Got it!

Just use another array to keep track of things:<BR><BR><BR>function ArrayIsInArray(MyFirstArray, MySecondArray)<BR>&#039;Determine if MyFirstArray is in MySecondArray<BR> dim temp()<BR> for each thing in MySecondArray<BR> counter=0<BR> redim temp(ubound(thing))<BR> for each piece in thing<BR> if IsArray(piece) then<BR> IsIn=ArrayIsInArray(MyFirstArray, piece)<BR> if IsIn then <BR> temp(counter)=true<BR> else<BR> temp(counter)=false<BR> end if<BR> counter=counter+1<BR> else<BR> if piece=MyFirstArray(counter) then <BR> temp(counter)=true<BR> else<BR> temp(counter)=false<BR> end if<BR> counter=counter+1<BR> end if<BR> next<BR> IsIn=true<BR> for each piece in temp<BR> if not piece then IsIn=false<BR> next<BR> if IsIn then Exit For<BR> Next<BR> ArrayIsInArray=IsIn<BR>end function<BR>

#### Posting Permissions

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