Page 1 of 1

Using Arrays to compare 2 tables

Posted: Thu Apr 09, 2015 4:44 pm
by no1g8tor96
I have some data in table one that i need to matchup with table 2. By email address. (see attachment)
I then need to put the matching line in table 1 in table 3 and will export table 3 to a text file.

I have never used arrays before and think it would be the fastest to do this.

this is what I have so far and it seems to put them in the arrays but I have tried everything else i could find to match them and its not working.
local tFirstArray, tsecondArray
on mouseUp
set the itemdel to tab
put "" into field "text3"
put line 1 of fld"text1" & cr into fld"text3"
put fld"lc1" into tLineCt1
put fld"lc2" into tLineCt2


repeat for each line tLine in fld"text1"
put it into tFirstArray[tLine]
end repeat

combine tFirstArray by return and tab
put the number of lines of tFirstArray into fld"lc1"


repeat for each line tLine2 in fld"text2"
put it into tsecondArray[tLine2]
end repeat

combine tsecondArray by return and tab


now what???

Thank you for any help you can give.

Re: Using Arrays to compare 2 tables

Posted: Thu Apr 09, 2015 7:25 pm
by phildavis
Hi no1g8tor96 -

Here is one way to do what you want, assuming I understood your goal correctly. I haven't tested it but it should work (famous last words!):

Code: Select all

on mouseUp
    -- get the list of email addresses without other chars in each line
    get fld 2 -- the list of emails to match against
    split it by column
    put it[2] into tEmailList -- now this contains only email addresses
    
    -- get lines in original list whose emails match an email in tEmailList
    put fld 1 into tOriginalList
    set the itemDelimiter to tab
    repeat for each line tLine in tOriginalList
        if item 3 of tLine is among the lines of tEmailList then
            put tLine & CR after tNewList
        end if
    end repeat
    
    -- display the selected lines
    put tNewList into fld 3
end mouseUp

Re: Using Arrays to compare 2 tables

Posted: Thu Apr 09, 2015 9:54 pm
by no1g8tor96
Phil

Worked like a charm.

Thank you so much.

Michael