Syntax to increment variable names in repeat loop

Nonsanity form at nonsanity.com
Tue May 24 09:56:56 EDT 2011


Arrays are the way to go there, but if you really do need to work with
constructed variable names, do is probably the only way to set such a value.
The following code clip shows how you can get the value of a constructed
variable name:

put 111 into var1
put 222 into var2
put 2 into whichVar
put merge( "[[var" & whichVar & "]]" ) into msg

 ~ Chris Innanen
 ~ Nonsanity


On Tue, May 24, 2011 at 7:47 AM, Keith Clarke <
keith.clarke at clarkeandclarke.co.uk> wrote:

> Thanks, Jim, The 'do' command looks useful as a mechanism for combining
> disparate elements - I'll add it to my armoury.
>
> The multi-dimensional array should keep the XML strings related but
> separate for post processing.
> I'm also setting a custom property on the stack as the array - to provide
> simple database-free persistence over time and across cards, should I need
> to access the XML (or more likely, cross-reference the keys) from elsewhere
> in the stack.
> Best,
> Keith..
>
> On 24 May 2011, at 12:31, Jim Ault wrote:
>
> > On May 24, 2011, at 2:12 AM, Keith Clarke wrote:
> >
> >> Hi folks,
> >> I have a repeat loop with tCycle = 1 to 10 and for each repeat, I need
> to put something into a new variable, specific to the particular cycle -
> tResultCycle1, tResultCycle2...  tResultCycle10.
> >>
> >> How does one script the creation of a unique variable for each loop, as
> LiveCode doesn't seem to like the attempted simple variable name
> concatenation in...
> >>
> >>     put "something" into tResult & tCycle
> >>
> >> I'm guessing I need to define the variable's name before using it, but
> 'variableNames' doesn't seem to fit the bill and as the dictionary doesn't
> even have an entry for 'variable' (so they're obviously not important!), I'm
> struggling to find any seed terms to search the list archives.
> >>
> >> Then again, maybe I'm missing something fundamental here - my default
> state with LiveCode, it seems! :-)
> >
> >
> > The   'do'  command is the common way to do this
> >
> > repeat with k = 1 to 10
> >    -- build thisVar for this loop
> >   do  "put thisVar into newVar" & k
> > end repeat
> >
> > You can also use
> > line k of fld storageFld
> > or
> > line k of aggregateVar
> > or
> > set the k of this card to thisVar
> > or
> > as you have done, use a multi dimensional array
> >
> > Minor advantage to custom props is they can be stored in the stack file.
>  This is good for bulding things like a list of path names and ftp site URLs
> that need to be kept with the stack and are not part of user data or
> preferences.
> >
> > Hope this helps
> >
> > Jim Ault
> > Las Vegas
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list