repeat string: how ?
Jan Decroos
jan.decroos at groepvanroey.be
Mon Nov 18 05:03:01 EST 2002
use-revolution at lists.runrev.com writes:
>repeat string: how? (Alex Rice)
We use a function which can be used to initialize of list of strings or numbers.
Use it like :
initcontainer("n",50) --> returns a list of 50 lines from 1 to 50
initcontainer("n",50,101) --> returns a list of 50 lines from 101 to 150
initcontainer("n",50,101,2) --> returns a list of 50 lines from 101 to 199
(step 2)
initcontainer("n",50,101,2,comma) --> returns a list of 50 items from 101 to
199
initcontainer("s",50,"Revolution") --> returns a list of 50 lines each with
"Revolution"
initcontainer("s",50,"Revolution",tab) --> returns a list of 50 tab separated
'items' "Revolution"
This prevents re-scripting repeat loops again and again....
function InitContainer pKind, pNum
if pNum <= 0 then return("")
if pKind = "s" then put "t" into pKind
put CR into lSeparator
if (pKind = "t" and (the paramCount < 3 or the paramCount > 4)) or (pKind =
"n" and (the paramCount < 2 or the paramCount > 5)) then StopWithMessage
"Invalid number of arguments !"
if pKind = "t" then
put the param of 3 into lValue
if the ParamCount = 4 then
put the param of 4 into lSeparator
end if
else
put 1 into lValue
put 1 into lStep
if the ParamCount >= 3 then
if the param of 3 is a number then
put the param of 3 into lValue
if the ParamCount >= 4 then
if the param of 4 is a number then
put the param of 4 into lStep
if the ParamCount = 5 then
put the param of 5 into lSeparator
end if
else put the param of 4 into lSeparator
end if
else put the param of 3 into lSeparator
end if
end if
if pKind = "n" then put "add lStep to lValue" into lAddStep
else put "" into lAddStep
put "" into lResult
do "repeat pNum-1"&CR&\
" put lValue&lSeparator after lResult"&CR&\
" "&lAddStep&CR&\
"end repeat"
put lValue after lResult
return(lResult)
end InitContainer
Jan
More information about the use-livecode
mailing list