Find difference between 2 flds

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Find difference between 2 flds

Post by Simon » Thu May 08, 2014 5:06 am

Hello forumer's, (??)
I have seen and this:
http://forums.runrev.com/phpBB2/viewtop ... =7&t=16184
with it's nifty split/combine but now I need the difference between 2 fields
fld 1
Hello
World
Red

fld 2
World
Blue
Hello
Green

Note that there are duplicates but not in the same order and differences.
I think I'd like an output
fld 1 -Blue, -Green
fld 2 -Red
or maybe the other way, doesn't matter
fld 1 Red
fld 2 Blue,Green
I'm sure there is some kind of nifty array method to do this.

Any ideas?

Simon
Edit (Bad Post!)
I have tried using an array but can't get my head around the different order.
I can do this with lineOffset but thought I could learn more about array manipulations for larger datasets.
And yes I'd dump the fields into variables first.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Find difference between 2 flds

Post by bn » Thu May 08, 2014 9:38 am

Hi Simon,

here is a way to find unique entries in each of two lists. I uses the "split ... as list" variant of split.
Then it deletes indexes (variables) from the two arrays crosswise to arrive at the unique indexes in each of the arrays.

Code: Select all

on mouseUp
   put field "f1" into tF1
   put field "f2" into tF2
   
   -- split with return as set will use the lines of the list as index
   split tF1 with return as set
   split tF2 with return as set
   
   -- create a copy of the arrays to work on for the result, see below
   put tF1 into tF1Res
   put tF2 into tF2Res
   
   -- delete every index in tF2 that is also in tF1 (= duplicates)
   repeat for each key aKey in tF1
      delete variable tF2Res[aKey]
   end repeat
   
   -- now delete every index in tF1 that is also in tF2 (= duplicates)
   repeat for each key aKey in tF2
      delete variable tF1Res[aKey]
   end repeat
   
   put "unique in field 1 compared to field 2: " & cr &  the keys of tF1Res into field "fRes"
   
   put cr & cr & "unique in field 2 compared to field 1: " & cr & the keys of tF2Res after field "fRes"
   
end mouseUp
Kind regards
Bernd, a forumer :)

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Find difference between 2 flds

Post by [-hh] » Thu May 08, 2014 11:19 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 3:24 pm, edited 2 times in total.
shiftLock happens

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Find difference between 2 flds

Post by Simon » Fri May 09, 2014 12:39 am

Thank You!

Bernd,
"delete variable tF2Res[aKey]" that is what I was looking for, couldn't get my head around it.

Hermann,
I remember this stack when it was first posted, impressive stuff. I have to improve my filing technique.

Thanks again,
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Find difference between 2 flds

Post by [-hh] » Fri May 09, 2014 5:00 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 3:25 pm, edited 1 time in total.
shiftLock happens

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Find difference between 2 flds

Post by FourthWorld » Fri May 09, 2014 5:18 am

[-hh] wrote:Hope you and others will open their archive of posted stacks and helpful snippets, with tags to make them findable.
I think I missed something: is RevOnline not working now?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Find difference between 2 flds

Post by [-hh] » Fri May 09, 2014 5:31 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 3:25 pm, edited 1 time in total.
shiftLock happens

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: Find difference between 2 flds

Post by bn » Fri May 09, 2014 10:11 am

RevOnline does work very well for me in 6.6.2 RC3.

The problem seems to be that hanging/not working is different for different users and the bug(s) are difficult to reproduce. But I hope it is getting there. I did not try to upload via LC 6.6.2 RC3 yet.
Bug 11387

Kind regards
Bernd

Post Reply