Here's how to add an item to the end of a list
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 222
- Joined: Thu Jul 01, 2010 11:50 am
Here's how to add an item to the end of a list
I'm replacing my original post with this one, because the way I thought I came up with for easily adding an item to the end of a list without manually inserting commas, well, I can't get it to work now. I'd delete this thread except I don't have that ability.
So, the most compact way to add an item to the end of a list is put "",newItem after theList.
So, the most compact way to add an item to the end of a list is put "",newItem after theList.
Last edited by MichaelBluejay on Fri Oct 25, 2019 8:34 pm, edited 2 times in total.
-
- VIP Livecode Opensource Backer
- Posts: 9647
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Here's how to add an item to the end of a list
Michael.
Your snippet will not compile, you need to:
Now then:
yields ""figs,berries,cherries", LC is ignoring the "last+" portion, as it often does with spurious words. This "feature" of LC can throw you. It does me. I wish the parser was more strict.
Keep having fun playing around. Discovering that LC will create the correct number of chunks when asked is cool, eh?. Try this;
Write back any time with all you discover, as well as complaints.
Craig
Your snippet will not compile, you need to:
Code: Select all
put "figs" into item (num(items of tList )+1) of tList
Code: Select all
on mouseUp
put "apples,berries,cherries" into tList
put "figs" into item last+1 of tList
end mouseUp
Keep having fun playing around. Discovering that LC will create the correct number of chunks when asked is cool, eh?. Try this;
Code: Select all
put "apples,berries,cherries" into tList
put "figs" into item 10 of tList
Craig
-
- Posts: 222
- Joined: Thu Jul 01, 2010 11:50 am
Re: Here's how to add an item to the end of a list
Well, I was sure it worked for me, but now I can't get it to. I'm wondering if there's maybe some small syntax thing I'm missing.
Guess I'm back to manually inserting commas.
I'd delete this thread except there's no way to do that as a basic user.
Guess I'm back to manually inserting commas.
I'd delete this thread except there's no way to do that as a basic user.
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: Here's how to add an item to the end of a list
You write "newItem & comma". Write "comma & newItem".
A bit more compact:
A bit more compact:
Code: Select all
put "",newItem after theList -- use value of variable newItem
put ",abcd" after theList -- use value
shiftLock happens
-
- Posts: 222
- Joined: Thu Jul 01, 2010 11:50 am
Re: Here's how to add an item to the end of a list
Thank you. I do like "",newitem more than comma & newItem. It's easier to tell at a glance that we're appending an item to the list.