Adding Numbered Line to a Numbered List and Renumbering List
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Adding Numbered Line to a Numbered List and Renumbering List
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
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
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
-
- VIP Livecode Opensource Backer
- Posts: 9656
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: Adding Numbered Line to a Numbered List and Renumbering List
Hi.
Will pseudoCode do?
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:
Craig Newman
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
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
Re: Adding Numbered Line to a Numbered List and Renumbering List
My opinion, this is faster:
from:
to
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>"
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>"
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w
-
- VIP Livecode Opensource Backer
- Posts: 7227
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Adding Numbered Line to a Numbered List and Renumbering List
@Craig, wouldn't "is a number" be faster? There's also "is an integer" and some others.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com