naming variables...

Brian Yennie briany at qldlearning.com
Wed May 4 08:09:37 EDT 2005


Yikes. I hope RunRev fixes this- I've seen it come up at least twice 
now on the list and it's an obvious scripting error.
The solution is to use the "do" command. This is similar to the "eval" 
function you find in many other languages- basically you dynamically 
generate the line of code, and then "do" will execute it at runtime.

## "do" something
repeat with x=1 to 20
     put ("fld a"&x&" into myVar"&x) into myCode
     ## myCode => the string "put fld a1 into myVar1"
     do myCode
end repeat

One cool sidenote- you can also use the "do" command to execute code 
from any other OSA scripting language installed if you are on MacOS, 
which usually means AppleScript.

The other way to access "outside" code is to use shell() in order to 
run command-line commands, but now I'm straying...

HTH,
Brian

> Hello all,
>
> how does it come that the simple "How do I create and use a numbered 
> set of variables?" example
> does not work in 2.5.1 ?
>
>
> I badly need to collect contents of flds into variables which are used 
> later in the script...
>
>  repeat with x = 1 to 20
>     put fld ("a"&x) into ("myVar" & x)
>   end repeat
>
> --> returns error : bad destination ???



More information about the use-livecode mailing list