PC Review


Reply
Thread Tools Rate Thread

ARRAY SEARCH PROBLEM !!!

 
 
jay dean
Guest
Posts: n/a
 
      8th Jul 2009
Hi -

I have 2 arrays: ArrA and ArrB. Each slot in each array contains
characters delimited by comma ",". I need to check if for every slot
content in ArrA, all members of any slot(s) in ArrB are there. ArrA and
ArrB don't necessarily have the same size or length.I just used array
lengths of 3 for ArrA and 4 for ArrB for simplicity but the actual
array slots can be lengthier.

Example:
If ArrA contains:
ArrA(0)= A,BB,C,FF,X
ArrA(1)= 88,VV,J,B,79
ArrA(2)= U,KL,MN,6,44
 
Reply With Quote
 
 
 
 
keiji kounoike
Guest
Posts: n/a
 
      8th Jul 2009
This is one way, though this doesn't satisfy your request for having
minimum loops or even no loops, but rather having maximum loops.

Sub Searchtest()
Dim ArrA(2), ArrAA
Dim ArrB(3), ArrBB
Dim i As Long, j As Long, k As Long
Dim found As Boolean

ArrA(0) = "A,BB,C,FF,X"
ArrA(1) = "88,UU,J,B,79"
ArrA(2) = "U,KL,MN,6,44"
ArrB(0) = "10,B,CC"
ArrB(1) = "C,A,FF"
ArrB(2) = "44,KL,MN"
ArrB(3) = "79,88,B"

For i = 0 To UBound(ArrA)
For j = 0 To UBound(ArrB)
found = True
ArrAA = Split(ArrA(i), ",")
ArrBB = Split(ArrB(j), ",")
For k = 0 To UBound(ArrBB)
If IsError(Application.Match(ArrBB(k), ArrAA, 0)) Then
found = False
Exit For
End If
Next
If found Then
MsgBox ArrB(j) & " Found in ArrA(" & i & _
") = { " & ArrA(i) & " }"
End If
Next
Next
End Sub

Keiji

jay dean wrote:
> Hi -
>
> I have 2 arrays: ArrA and ArrB. Each slot in each array contains
> characters delimited by comma ",". I need to check if for every slot
> content in ArrA, all members of any slot(s) in ArrB are there. ArrA and
> ArrB don't necessarily have the same size or length.I just used array
> lengths of 3 for ArrA and 4 for ArrB for simplicity but the actual
> array slots can be lengthier.
>
> Example:
> If ArrA contains:
> ArrA(0)= A,BB,C,FF,X
> ArrA(1)= 88,VV,J,B,79
> ArrA(2)= U,KL,MN,6,44
> .
> .
> .
>
> And ArrB contains:
> ArrB(0)= 10,B,CC
> ArrB(1)= C,A,FF
> ArrB(2)= 44,KL,MN
> ArrB(3)= 79,88,B
> .
> .
> .
> Then I want to take ArrB(0),ArrB(1),ArrB(2),ArrB(3) and compare EACH to
> ArrA(0). If ALL the elements in any ArrB(x) are found in ArrA(0) then a
> messgBOx will show those found to be subsets. In this case, only
> elements of ArrB(1) are all found in Arr(0)... so we'll have Msgbox
> 'C,A,FF found'
>
> Then the macro will compare ArrB(0),ArrB(1),ArrB(2),ArrB(3) with
> ArrA(1). In this case, only elements of ArrB(3) can all be found in
> ArrA(1), so message box shows "79,88,B found'. Then we will compare all
> the ArrB to ArrA(2), ArrA(3), etc.. whenever ALL elements of ANY ArrB
> slot(s) are found in ANY element in ArrA, the Msgbox shows up with the
> subsets names.
>
> I think this will be a little tough but I am looking for a solution with
> minimum loops or even no loops (if at all possible).
>
> Any help will be appreciated.
>
> Thanks
> Jay Dean
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array problem: Key words-Variant Array, single-element, type mismatch error davidm Microsoft Excel Programming 7 11th Jun 2011 12:01 AM
search an array for values contained in another array =?Utf-8?B?Q2hlZXItUGhpbC1seQ==?= Microsoft Excel Programming 0 12th Apr 2007 09:44 PM
Binary search class: small problem retrieving the last element in the ordered array Bob Rock Microsoft C# .NET 11 29th Dec 2006 10:42 PM
SEARCH EXCEL ARRAY FOR NON-VOIDS AND ENTER INTO ANOTHER ARRAY, =?Utf-8?B?Uk9TRSBUSEUgUkVE?= Microsoft Excel Programming 1 31st Dec 2004 06:01 PM
Re: Need help writing a search procedure to search thru an array. Fergus Cooney Microsoft VB .NET 0 6th Oct 2003 07:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:38 PM.