number of lines inaccurate, sometimes?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Location: Virginia, USA
Contact:

number of lines inaccurate, sometimes?

Post by trenatos » Fri Apr 24, 2015 7:20 pm

I'm trying to count the number of lines of a scrolling field (Without wrapping)

There are two ways I know of, the number of lines of field "input", and the second is setting the itemdelimiter and counting items.

But both of these seem inaccurate.

As I hit enter/backspace, adding and removing lines, the number of lines do not always count empty lines, if I put any character on a new line, it's counted properly.

Is there a better way of doing it? Or am I just using it wrong?
Marcus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9801
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: number of lines inaccurate, sometimes?

Post by FourthWorld » Fri Apr 24, 2015 7:28 pm

If it's not including blank lines in the middle of a list in the count then that would be a bug, But if it's just the last blank line that's by design: delimiters are endings, so a CR at the end of a line will indeed place the cursor below it to allow creation of a new line, but that trailing CR is not a line in itself.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Location: Virginia, USA
Contact:

Re: number of lines inaccurate, sometimes?

Post by trenatos » Fri Apr 24, 2015 7:31 pm

It's only when the last line is blank (Has no content)

I can have a whole bunch of blank lines, and the last one is not counted.
Marcus

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Location: Virginia, USA
Contact:

Re: number of lines inaccurate, sometimes?

Post by trenatos » Fri Apr 24, 2015 7:36 pm

Ok, I solved it by doing:

if the last character of field "mainInput" is lf then
put the number of lines of field "mainInput" + 1 & cr after temp
end if

All it's for is displaying the line count next to the line, this seems to work for now
Marcus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9801
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: number of lines inaccurate, sometimes?

Post by FourthWorld » Fri Apr 24, 2015 7:45 pm

I can have a whole bunch of blank lines, and the last one is not counted.
That sounds consistent with the design, since a line can contain an empty value.

Consider:
something<CR>
somethingelse<CR>
<CR>
anotherThing<CR>

In that example there a four lines, though one of them (the third one) is empty.

Here the number of lines is also four:

something<CR>
somethingelse<CR>
<CR>
<CR>

Keep in mind that the position of the cursor doesn't denote the existence of a line in the data, it's merely a convenience for you to begin create new content at that position but is not a line per se until something is added there, even if the only thing that gets added there is a CR.

Just remember that delimiters are endings and hopefully it'll become clearer.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

trenatos
Posts: 189
Joined: Wed Jul 03, 2013 6:46 am
Location: Virginia, USA
Contact:

Re: number of lines inaccurate, sometimes?

Post by trenatos » Fri Apr 24, 2015 8:10 pm

Yeah it makes sense now
Marcus

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”