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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching Array values 3

Status
Not open for further replies.

KM8888

Programmer
Nov 21, 2011
69
US
Hi everyone, I had posted this in the VBScript area as it does involve using PCOMM and VBScript but I couldn't find the exact kind of answer I was looking for and this forum has helped me out despite the little differences between my programs so thought I would reach out here as well!


Hopefully I can explain well enough for you experts to understand. Basically I am trying to see if values within two arrays match so it can create a third array that displays those values......... For example

Array()
Array1()

Arrays run in separate For loops kind of like this

For i = 0 to #

Array(i) = .gettext (row, cursor)

i = i+1

Next

Repeat the above step for Array1()

What can I do to see what values that I got from the first array match with the second one? So if the first array has like

Apple
Banana
Coconut
Orange

And the second has

Apple
Strawberry
Orange
Kiwi

Array and Array1 = Orange and Apple

Hopefully I explained that well and it's possible to pull off, any information anybody can provide will surely get a star, I will probably have a follow up question as well. Thanks all :)


Inappropriate post?
If so, Red Flag it!


 
Hey Skip,

That is a nice way to go at it, I should have mentioned before, it's possible that Orange02 might also exist in that array and I only want to match it with 01, with that specific line of code it would match every number after the word Orange right? So I guess the defining of the 01 is key.

Thanks again :)
 


so could there be Orange03, Orange04, ... etc?

And exactly WHAT is the general matching logic that would apply in every case?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
What about this ?
If UCase(ary1(i)) & "01" = UCase(ary2(j)) Then


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hey PHV, it doesn't seem to returning a match when using that :( I guess because it's adding the 01 to the end of each in the first array so then it can't possibly match ary2?

I'll try to answer as best as possible Skip, basically I have a bunch of values I am entering in manually so like Orange, and say on the side of the screen there are values that are default values that can vary depending. But in that lot there could be like Orange, Orange01, Orange02 etc. So I can easily match up Orange and Orange and add it to the array but if I want to add Orange01 to the array as a "match" as well I'm having difficulty, without of course leaving out 02 or other numbers I don't want to include.

Thanks :)
 


OK, so why wouldn't the solution posted 17 Apr 12 14:31 work?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
if ucase(ary1(i)) = left(ucase(ary2(j)), len(ary1(i)) then

Sorry I may have been looking at it the wrong way but I thought by just reading it, isn't it just matching up if everything before is the same? So if the ary2 value is orange 2 it is cutting back to orange to match up with ary1 orange but wouldn't this produce a match in the case where orange02 exists because it's cutting back to the length of ary1 so orange02 would cut orange therefore orange = orange again? Or am I wrong on that aspect? Just looking to match it with orange01 and no other numbers if possible.

Thanks :)
 


I am totally confused!

Please post several specific examples using Orange... what you WANT to match and NOT and WHY.
[tt]
Orange Orange01 ????
Orange Orange02 ????
Orange Banana ????
[/tt]

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Just looking to match it with orange01 and no other numbers
So why wouldn't the solution posted 17 Apr 12 15:04 work?
 
Sorry for the confusion guys.

I am just looking to match Orange with any existence of Orange01, if Orange02 is there I do not want it to match up with that value, but since Orange02 also exists in the array with Orange01 I'm having trouble matching specifically to 01.

I tried that piece of code PHV but it wasn't stating a match existed when I tested it. I assume it wasn't producing a match because it was basically saying does Orange + 01 = Orange and since it now was Orange01 it wouldn't be matching up with just the regular Orange. Perhaps I'm wrong on that?

If I did that bit of code except take out the "If" portion and just said it DOES equal that then would I be able to sort it out then? Or something along those lines?

Thanks
 


But that is EXACTLY what PHV's code is indicating
Code:
If UCase(ary1(i)) & "01" = UCase(ary2(j)) Then
If ary1 contains 'Orange' and ary2 contains 'Orange01' then the statement WILL be TRUE when those two values are encountered!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Hm, okay sorry guys, must be my poor testing ability, I'll give it another go and see if I can get it to work.

Thanks :)
 
I'll give it another go and see if I can get it to work
And the result is ?
 
Hey sorry for not updating!

I couldn't really pull off that line of code, I'm not sure if it was because of PCOMM unable to identify that or just my amateur ways but I had to take another route of creating two arrays 1 for the name and another for the numbers, then had to check if array = array and also number array = 01 then match it. Obviously probably way more complex then it ever needed to be but gets the job done thus far. Thanks everyone again for their help regarding it!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top