I am having no luck with the union command. The documentation says
Examples:
union monthlyPayments with quarterlyPayments
Use the union command to combine two arrays, eliminating duplicate elements
I know the variables, are arrays, but what do they actually look like? Can anyone give me a simple sample script I can copy and paste into, say, a button to put the get union of two arrays, just as an illustration? I tried with
union array with testArray
where array="a,b,c,d" and testArray="c,d,e,f", hoping that the union command put yield "a,b,c,d,e,f". Obviously I am way off. Thanks in advance.
Can't figure out "union"
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 9
- Joined: Wed Feb 21, 2007 12:18 am
- Contact:
Re: Can't figure out "union"
Hagen,
"a,b,c,d" is not an array. It is a string containing characters delimited by commas. If you want to turn this into an array, you can do this:
This produces an array with 5 keys. The keys are displayed in the message box.
Best,
Mark
"a,b,c,d" is not an array. It is a string containing characters delimited by commas. If you want to turn this into an array, you can do this:
Code: Select all
on mouseUp
put "a,b,c,d,e" into x
split x by comma
put the keys of x
end mouseUp
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: Can't figure out "union"
professorhagen,
try this in a button.it will put the union of the keys of the two arrays into the message box:
Bernd
try this in a button.
Code: Select all
on mouseUp
put "1,2,3,4,5,6" into tItemList
put "a,b,c,d" into tKeyList1
put "e,f,g,h" into tKeyList2
-- create first array
repeat with i = 1 to 4
put any item of tItemlist into tArray1[item i of tKeyList1]
end repeat
-- create second array for the union
repeat with i = 1 to 4
put any item of tItemList into tTestArray[item i of tKeyList2]
end repeat
union tArray1 with tTestArray
put the keys of tArray1 into tTheKeys
-- remember the keys of an array are not sorted
sort tTheKeys
put tTheKeys
end mouseUp
regardsa
b
c
d
e
f
g
h
Bernd