Using Arrays to compare 2 tables

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
no1g8tor96
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 16
Joined: Fri Aug 02, 2013 12:14 am

Using Arrays to compare 2 tables

Post by no1g8tor96 » Thu Apr 09, 2015 4:44 pm

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.
Attachments
Screen Shot 2015-04-09 at 11.32.05 AM.png

phildavis
Posts: 2
Joined: Sat Apr 08, 2006 6:24 pm
Location: West Linn, Oregon USA

Re: Using Arrays to compare 2 tables

Post by phildavis » Thu Apr 09, 2015 7:25 pm

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
Phil Davis

no1g8tor96
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 16
Joined: Fri Aug 02, 2013 12:14 am

Re: Using Arrays to compare 2 tables

Post by no1g8tor96 » Thu Apr 09, 2015 9:54 pm

Phil

Worked like a charm.

Thank you so much.

Michael

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”