Filter Script & Patterns & Regex

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5330
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Filter Script & Patterns & Regex

Post by dunbarx » Wed Dec 13, 2017 10:01 pm

I am very leery of the "hidden" property. Because hidden lines collapse the other lines, it can be very disconcerting that a field that has five lines only shows three, say. Never mind returns below the field, which are annoying enough.

The hidden property is only useful when actually viewing lines by people with eyes. That is precisely the time that extra care has to be taken so that the number of lines does not conflict with any visual measure, and especially with synchronized scrolling fields.

Craig

chipsm
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 199
Joined: Wed May 11, 2011 7:50 pm
Location: Southern California

Re: Filter Script & Patterns & Regex

Post by chipsm » Wed Dec 13, 2017 10:11 pm

Thanks for the suggestion Jim.
Clarence Martin

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

Re: Filter Script & Patterns & Regex

Post by bogs » Wed Dec 13, 2017 10:13 pm

While it is non destructive, Craig rightly points out there are possible 'gotchas' down the line if you need to count the lines. In this example, line 2 is set to 'hidden'.
Image
If you went this route, and later needed to count lines, you'd have to make an allowance for the ones set to hidden, for example (psuedo code)

Code: Select all

// counting the lines
if the hidden of line x is not true then add 1 to myVar
put "the number of lines are " & myVar
Just something to keep in mind.
Image

jiml
Posts: 150
Joined: Sat Dec 09, 2006 1:27 am
Location: Los Angeles

Re: Filter Script & Patterns & Regex

Post by jiml » Thu Dec 14, 2017 1:08 am

Code: Select all

put the number of lines of fld 1
would correctly return 4 in that example, even though line 2 is hidden.

Code: Select all

put line 2 of fld 1
would return:
this is line 2

You are correct that you would need to use a repeat loop and the IF statement you provided in order to count the hidden lines.

It might be nice if these worked:

Code: Select all

put the number of hidden lines of fld 1

Code: Select all

hide line 2 of fld 1
but they don't. :(

If lines 2 and 4 were hidden this would give you a list of the hidden lines - "2,4" :

Code: Select all

function countHidden whatFld
   repeat with x = 1 to the number of lines of fld whatFld
      if the hidden of line x of fld whatFld is true then put x & comma after output
   end repeat
   delete char -1 of output
   return output
end countHidden

Code: Select all

put the number of items of counthidden(1)
gives a count of the hidden lines - 2.

It would be easy to modify the above function to return an array that lists both hidden and shown lines - [hiddenLines[2,4],shownLines[1,3]]

Jim Lambert

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

Re: Filter Script & Patterns & Regex

Post by bogs » Thu Dec 14, 2017 2:55 am

I completely agree it is no great chore or difficulty to get the accurate count, as I said, just something to keep in mind if, for instance, it looked like the result you wanted and later couldn't figure out why the field returns 4 lines, and you only see 3.

You wrapped it up nicely in that function, very neat :D
Image

Post Reply

Return to “Talking LiveCode”