repeat string: how ?
Ken Ray
kray at sonsothunder.com
Mon Nov 18 13:26:01 EST 2002
Jan,
How about:
function InitContainer pKind,pCount,p1,p2,p3
if pCount<=0 then return("")
if pCount= "" then return "Invalid number of arguments!"
put 1 into tNumSteps
put 1 into pStartNum
switch pKind
case "n"
put p1 into pStartNum
put p2 into tNumSteps
put p3 into tSeparator
break
case "s"
put p1 into tString
put p2 into tSeparator
break
end switch
put "" into tResult
set the lineDel to tSeparator
repeat with x = pStartNum to (pStartNum+pCount) step tNumSteps
if pKind = "n" then put x into line x of tResult
if pKind = "s" then put tString into line x of tResult
end repeat
return tResult
end InitContainer
This is off the top of my head and hasn't been tested, but it eliminates a
bunch of "do" statements (which will improve performance) and is a bit
shorter as well...
Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/
----- Original Message -----
From: "Jan Decroos" <jan.decroos at groepvanroey.be>
To: <use-revolution at lists.runrev.com>
Sent: Monday, November 18, 2002 3:57 AM
Subject: RE: repeat string: how ?
> 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
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
More information about the use-livecode
mailing list