Re: repeat with each
Hi Paul, I should have read it one more time before posting. This should be the correct script: repeat for each word myWord in field "Just One" put myWord & comma after myNewdata end repeat delete last char of myNewData sort items of myNewData put myNewData into field "Just One" -- Best regards, Mark Schonewille Economy-x-Talk Consulting and Software Engineering Homepage: http://economy-x-talk.com Twitter: http://twitter.com/xtalkprogrammer KvK: 50277553 Installer Maker for LiveCode: http://qery.us/468 Buy my new book "Programming LiveCode for the Real Beginner" http://qery.us/3fi LiveCode on Facebook: https://www.facebook.com/groups/runrev/ On 9/22/2014 15:28, Paul Foraker wrote: On Mon, Sep 22, 2014 at 6:13 AM, Mark Schonewille < m.schonewi...@economy-x-talk.com> wrote: repeat for each word myWord in field "Just One" put thisWord & comma after myNewdata end repeat sort items of myNewData put char 1 to -2 of myNewData into field "Just One" This loop generates a string that (1) starts with an empty item and (2) repeats the word "thisWord", deleting the last "d". (1) The last item after the loop finishes is empty -- the comma at the end. After the sort, however, that comma is at the front of the variable. A simple solution would be to replace the last line with put char 2 to -1 of myNewData into fld "Just One" (2) Instead of "put thisWord", it should be "put myWord". Or, "repeat for each word thisWord" -- Paul ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: repeat with each
On Mon, Sep 22, 2014 at 6:13 AM, Mark Schonewille < m.schonewi...@economy-x-talk.com> wrote: > repeat for each word myWord in field "Just One" > put thisWord & comma after myNewdata > end repeat > sort items of myNewData > put char 1 to -2 of myNewData into field "Just One" > This loop generates a string that (1) starts with an empty item and (2) repeats the word "thisWord", deleting the last "d". (1) The last item after the loop finishes is empty -- the comma at the end. After the sort, however, that comma is at the front of the variable. A simple solution would be to replace the last line with put char 2 to -1 of myNewData into fld "Just One" (2) Instead of "put thisWord", it should be "put myWord". Or, "repeat for each word thisWord" -- Paul ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: repeat with each
Hi Larry, The variable thisWord contains a copy of the item in the field. It doesn't refer to the actual item. When you put "," after thisWord, you change the string that is stored in variable thisWord, but not the string that is stored in field justOne. If you want to change the contents of the field, you need to create an updated copy and replace the contents of the field with the copy, like this: repeat for each word myWord in field "Just One" put thisWord & comma after myNewdata end repeat sort items of myNewData put char 1 to -2 of myNewData into field "Just One" If you want to refer the items of the field directly, you can use repeat with: repeat with x = 1 to number of words of field "Just One" - 1 put comma after word x of field "Just One" end repeat sort items of field "Just One" I could imagine that the following may work too: replace space with comma & space in field "Just One" sort items of field "Just One" -- Best regards, Mark Schonewille Economy-x-Talk Consulting and Software Engineering Homepage: http://economy-x-talk.com Twitter: http://twitter.com/xtalkprogrammer KvK: 50277553 Installer Maker for LiveCode: http://qery.us/468 Buy my new book "Programming LiveCode for the Real Beginner" http://qery.us/3fi LiveCode on Facebook: https://www.facebook.com/groups/runrev/ On 9/22/2014 15:04, la...@significantplanet.org wrote: Hello, I have never been able to understand how to use the each form in a repeat statement. Can anyone explain why this code does not work? It is almost verbatim from the example in the LC dictionary. on mouseUp repeat for each word thisWord in field justOne put "," after thisWord end repeat sort items of field justOne end mouseUp It does not insert the commas. Supposedly the each form is a lot faster than using "put x + 1 into x" "put "," after word x of field justOne Thanks, Larry ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: repeat with each
Hi Larry, Am 22.09.2014 um 15:04 schrieb la...@significantplanet.org: > Hello, > > I have never been able to understand how to use the each form in a repeat > statement. > > Can anyone explain why this code does not work? It is almost verbatim from > the example in the LC dictionary. > > on mouseUp > repeat for each word thisWord in field justOne > put "," after thisWord > end repeat > sort items of field justOne > end mouseUp > > It does not insert the commas. Supposedly the each form is a lot faster than > using > > "put x + 1 into x" > "put "," after word x of field justOne "repeat for each ..." is READ-ONLY! Means you cannot modify thisWord here! Collect your data in a variable first, then write stuff back to field: ... ## Never forget to put QUOTES around object names! repeat for each word thisWord in field "justOne" put thisWord & "," after tNewVariable end repeat delete char -1 of tNewVariable sort item of tNewVariable put tNewVariable into fld "justOne" ... > Thanks, > Larry Best Klaus -- Klaus Major http://www.major-k.de kl...@major-k.de ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
repeat with each
Hello, I have never been able to understand how to use the each form in a repeat statement. Can anyone explain why this code does not work? It is almost verbatim from the example in the LC dictionary. on mouseUp repeat for each word thisWord in field justOne put "," after thisWord end repeat sort items of field justOne end mouseUp It does not insert the commas. Supposedly the each form is a lot faster than using "put x + 1 into x" "put "," after word x of field justOne Thanks, Larry ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode