Page 1 of 1
Compare Data from Array
Posted: Fri Oct 26, 2018 3:25 pm
by M.M
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
Re: Compare Data from Array
Posted: Fri Oct 26, 2018 5:24 pm
by dunbarx
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
Re: Compare Data from Array
Posted: Fri Oct 26, 2018 5:56 pm
by dunbarx
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
Re: Compare Data from Array
Posted: Wed Oct 31, 2018 12:07 am
by dunbarx
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