Page 1 of 1
Adding Numbered Line to a Numbered List and Renumbering List
Posted: Tue Jan 09, 2018 7:00 pm
by montymay
Hello
If you have a list of numbered lines in a field, numbered 1 through x, and you want to add numbered line i, where i =< x, what would be the method for renumbering the list? For example, you want to add the line "3) Oranges" to the following field:
1) Apples
2) Pears
3) Peaches
4) Cherries
so that it becomes:
1) Apples
2) Pears
3) Oranges
4) Peaches
5) Cherries
Thank you for your replies.
Monty
Re: Adding Numbered Line to a Numbered List and Renumbering List
Posted: Tue Jan 09, 2018 8:11 pm
by bogs
Wouldn't something like this work?
Code: Select all
repeat with x to the number of lines of myVar
// I am guessing the cherries etc. are in a var or array...
put line x & "your text" & cr after field "Field Name"
end repeat
Re: Adding Numbered Line to a Numbered List and Renumbering List
Posted: Tue Jan 09, 2018 8:12 pm
by dunbarx
Hi.
Will pseudoCode do?
Code: Select all
on mouseUp
put yourData into temp
put 3 into insertionLine -- you need to extract this number from your new line
put return & "3) Oranges" after line (insertionLine - 1) of temp
repeat with y = (insertionLine + 1) to the number of lines of temp
add 1 to the number at the beginning of line y of temp --very pseudo
end repeat
put temp into yourData
end mouseUp
Can you take it from here? If not, write back and I will give the whole thing, or someone will.
I have a handler in a library that I wrote about 30 years ago in HC. I use it everywhere:
Code: Select all
function onlyNumber tText
repeat for each char tChar in tText
if tChar is in ".0123456789" then put tChar after temp
end repeat
return temp
end onlyNumber
Craig Newman
Re: Adding Numbered Line to a Numbered List and Renumbering List
Posted: Wed Jan 10, 2018 4:57 pm
by MaxV
My opinion, this is faster:
from:
Code: Select all
set the htmlText of field 1 to "<ol><li>apples</li><li>Pears</li><li>Peaches</li><li>Cherries</li></ol>"
to
Code: Select all
set the htmlText of field 1 to "<ol><li>apples</li><li>Pears</li><li>Oranges</li><li>Peaches</li><li>Cherries</li></ol>"

Re: Adding Numbered Line to a Numbered List and Renumbering List
Posted: Wed Jan 10, 2018 6:59 pm
by jacque
@Craig, wouldn't "is a number" be faster? There's also "is an integer" and some others.