Scripting what should be a simple loop...

Alex Tweedly alex at tweedly.net
Fri Jul 9 19:43:37 EDT 2010


You do indeed need a 'do' statement - but the first half of the 
statement (dealing with the field) doesn't need it, only the second half.
So I would find it more readable to do

    put (fld "field" & i) into temp
    do "put temp into quote & "tVar" & quote & i

OK, it's marginally inefficient, but who cares compared to the 
readability :-)

-- Alex.

On 10/07/2010 00:34, Bob Sneidar wrote:
> You need a do statement. Otherwise you would need Macro Substitution which Runrev does not support.
>
> put "put fld"&&  quote&  "Field"&  i&  quote&&  "of group"&  quote&  AllFields&  quote&&  "into tvar"&  i into theCommand
> do theCommand -- careful of line wraps
>
> Easier to read is:
> put "put fld fieldi of group allfields into tvari" into theCommand
> replace "fieldi" with quote&  "field"&  i&  quote in theCommand
> replace "allfields" with quote&  "allfields"&  quote in theCommand
> replace "tvari" with quote&  "tVar"&  i&  quote in theCommand
> do theCommand -- remembering to check Bob for mistakes in his code
>
> Bob
>
>
> On Jul 9, 2010, at 4:23 PM, David C. wrote:
>
>    
>> Good grief! Will someone be so kind as to show me the proper way to
>> format my script...
>>
>> Let's say I have the following
>>
>> 1 group named "AllFields" containing:
>> 10 text fields, named Field1...Field10
>> 10 temporary variables named tVar1...tVar10
>>
>> All I want to do, using a loop, is to put the user supplied data
>> contained in each field into the corresponding, like-named variable. I
>> thought I could do something easy like this
>>
>> repeat for i = 1 to 10
>> put fld "Field"&  i of grp "AllFields" into tVar&  i
>> end repeat
>>
>> I know that I've done this before, but so far I've yet to find the
>> right format that will not cause an error when compiling the script
>> -and- would greatly appreciate it if some kind soul would rescue me
>> from this madness.
>>
>> FWIW, I recently had another fifty-something birthday, so I'm blaming it
>> all on an increasing case of dementia. As in:
>>
>> "Dementia (meaning "deprived of mind") is a serious loss of cognitive
>> ability in a previously unimpaired person, beyond what might be
>> expected from normal ..."
>>
>>
>> Best regards,
>> David C.
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>      
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>    




More information about the use-livecode mailing list