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
Compare Data from Array
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 9655
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Compare Data from Array
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:
You cannot have both.
But you can store multiple distinct strings by delimiting them:
Then you can examine either variable and retrieve any or all of the items within.
You might store that data in a field or custom property if you want it to survive sessions.
Craig Newman
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
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
Code: Select all
answer item 1 of order1 & comma & item 2 of order1 & return & item 1 of order2
Craig Newman
-
- VIP Livecode Opensource Backer
- Posts: 9655
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Compare Data from Array
I reread your post. You can do what you want. Assuming you have your starting data in a variable "temp":
You can assemble the array "myArray" to include the keys afterwards. Do you know how to do this?
Craig
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
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9655
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Compare Data from Array
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:
A bit wordy, but you should see what is happening.
Craig
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
Craig