Compare Data from Array

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
M.M
Posts: 4
Joined: Tue Aug 28, 2018 12:53 pm

Compare Data from Array

Post by M.M » Fri Oct 26, 2018 3:25 pm

Hi,

I have a short question how to compare a array.

e.g.:

Order1 This is product 1
Order1 This is product 2
Order 2 This is product 1

What is to do to compare the products from Order1?

Output to have:
Order 1 This is product1, this is product2
Order 2 This is product 1

Each Line is delimited with CR, each Item is delimited with Tab.

My idea is to create a repeat for each line loop...


Regs
Moritz

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Compare Data from Array

Post by dunbarx » Fri Oct 26, 2018 5:24 pm

Hi.

I would not use an array. Since you have two different "elements" ("...product 1" and "...product 2") associated with the "key" "Order 1", you will not be able to store them the way you want. It would be the same as trying to:

Code: Select all

put "X" into temp
put "Y" into temp
You cannot have both.

But you can store multiple distinct strings by delimiting them:

Code: Select all

put "This is product 1" & comma & "This is product 2" into order1
put "This is product 1" into order2
Then you can examine either variable and retrieve any or all of the items within.

Code: Select all

answer item 1 of order1 & comma & item 2 of order1 & return & item 1 of order2
You might store that data in a field or custom property if you want it to survive sessions.

Craig Newman

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Compare Data from Array

Post by dunbarx » Fri Oct 26, 2018 5:56 pm

I reread your post. You can do what you want. Assuming you have your starting data in a variable "temp":

Code: Select all

on mouseUp
   set the itemDel to tab
   repeat with y = 1 to the number of lines of temp
 put item 2 of line y of temp & return after myArray[item 1 of line y of temp]
end repeat
end mouseUp
You can assemble the array "myArray" to include the keys afterwards. Do you know how to do this?
Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Compare Data from Array

Post by dunbarx » Wed Oct 31, 2018 12:07 am

Have not heard from you, so I am throwing this into the ether.

Assuming you have your data in a fid 1, and you also have a fld 2:

Code: Select all

on mouseUp
   set the itemDel to tab
   repeat with y = 1 to the number of lines of fld 1
      put item 2 of line y of fld 1 & return after myArray[item 1 of line y of fld 1]
   end repeat
   
   combine myArray with return and comma
   replace comma with "" in myArray
   sort myArray ascending numeric by the last char of item 1 of each
   repeat with y = the number of lines of myArray down to 1
      if line y of myArray = "" then delete line y of myArray
   end repeat
   put myArray into fld 2
end mouseup
A bit wordy, but you should see what is happening.

Craig

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”