Adding Numbered Line to a Numbered List and Renumbering List

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
montymay
Posts: 145
Joined: Thu Jul 18, 2013 5:23 am

Adding Numbered Line to a Numbered List and Renumbering List

Post by montymay » Tue Jan 09, 2018 7:00 pm

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

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Adding Numbered Line to a Numbered List and Renumbering List

Post by bogs » Tue Jan 09, 2018 8:11 pm

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
Image

dunbarx
VIP Livecode Opensource Backer
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

Post by dunbarx » Tue Jan 09, 2018 8:12 pm

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

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: Adding Numbered Line to a Numbered List and Renumbering List

Post by MaxV » Wed Jan 10, 2018 4:57 pm

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>"
:lol:
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

jacque
VIP Livecode Opensource Backer
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

Post by jacque » Wed Jan 10, 2018 6:59 pm

@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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”