Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing two arrays

Status
Not open for further replies.

don2241

IS-IT--Management
Jun 1, 2001
57
AU
Hi!

I'm not to familiar with the VB syntax to be able to do what I want.

I have two dynamic arrays of type string that contains a word in a cell. I want to compare each cell in one array to each cell in another array. If there is a match I'm going to do something. I've tried to write a little pseudo code to better explain.


dim proArray() as string
dim suppArray() as string
dim proCount as long
dim suppCount as long

Pseudo code:
proCount = 0
do while (proArray() is empty <> true)

suppCount = 0
do while (suppArray() is empty <> true)
if (proArray(proCount) = suppArray(suppCount)
do my stuff....
suppCount = suppCount +1
else
suppCount = suppCount +1
end if
loop

proCount = proCount +1
loop



How would the actual VB code look like to be able to do this?

Thanks

M.



 
I would try to use a nested for loop. something similar to what's below.

Dim i as integer, j as integer
Dim Array1() as string, Array2() as string

... arrays get filled.

For i = 0 to ubound(Array1)
For j = 0 to Ubound(array2)
if Array1(i)=Array2(j) then
... do something
end if
next j
Next i

Thanks and Good Luck!

zemp
 
Hi!

Thanks for the code. Unfortunately it does not work because the IF statement will compare two arrays that contain nothing thus be true

My code that I tried

Dim pro As Integer
Dim supp As Integer

MsgBox (proArray(0)) ‘displays AAAAA
MsgBox (suppArray(0)) ‘displays BBBBB

For pro = 0 To UBound(proArray)
For supp = 0 To UBound(SuppArray)
If (proArray(pro) = SuppArray(supp)) Then
MsgBox (proArray(pro)) ‘nothing
MsgBox (SuppArray(supp)) ‘nothing
End If
Next supp
Next pro

Thanks

M.
 
To Zemp!

My mistake, sorry the code work the way I want

Thanks again

M.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top