filter issues

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
MauriceAndre
Posts: 9
Joined: Fri Aug 17, 2012 12:32 am

filter issues

Post by MauriceAndre » Mon Aug 17, 2015 6:37 pm

Hi everyone

the filter function seems very straightforward - yet I can't get it to work for me...
I'm using a text entry field to specify a filter word, that should then be used to filter the lines of a table field containing words in column 1, and numbers in column 2.

So, e.g.:

Code: Select all

filter tSource with tSearch into tResult  --- where tSource would be the full table, tSearch a searchstring, and tResult the desired subset of tSource, showing only lines matching tSearch.
Apparently I can't use the filter function on a table field directly, so I need to add some processing steps in between - but which?
Convert the table back into a string with certain delimiters > filter > convert it back into table format...?? Is there a simple & elegant way to do this?

Running my script variants just end up purging the content instead of filtering it.

thanks for your help,
Maurice

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: filter issues

Post by Simon » Mon Aug 17, 2015 6:56 pm

Hi Maurice,
I'd put the full table info into a custom property with an item delimiter (could be cr). Then when doing the search put the custom property into a variable, do the filter and replace the table with what is left.
The full table will always be available via the custom property.
You probably have seen empty cp's as they are in every control.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: filter issues

Post by FourthWorld » Mon Aug 17, 2015 6:58 pm

A table field is still just a field, so you can use:
put the text of field "MyTable" into tMyVar
put tMyVar into field "MyTable"
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: filter issues

Post by dunbarx » Mon Aug 17, 2015 7:11 pm

Apparently I can't use the filter function on a table field directly,
You can indeed. Perhaps you did not delimit properly:

Code: Select all

on mouseUp
   set the itemdel to tab
   filter items of fld "yourTableField without "yourStringHere"
end mouseUp
Craig Newman

MauriceAndre
Posts: 9
Joined: Fri Aug 17, 2012 12:32 am

Re: filter issues

Post by MauriceAndre » Mon Aug 17, 2015 8:14 pm

Simon, Richard and Craig - - -

thanks a lot for the prompt replies. Tried everything - but my bug must be in how I apply the filter?

Here's the full script:

Code: Select all

on mouseUp
   set the itemdel to cr
   
   put the text of fld "searchFrequency" into tSearch
   put the text of fld "WordFreq" into tSource
   
   filter items of tSource with tSearch into tResult
   
   put tResult into fld "wordFreq"
    
end mouseUp 
The original field (Simon, totally agree about using a cProp for persistance in later use) "wordFreq" that I want to overwrite - here it just gets purged, as before.

The field should just be repopulated / overwritten with what's in tResult var, no?? What am I missing...

Do filters have to come in a Regex flavor? Sorry, three guys helping - but still not getting it.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: filter issues

Post by Simon » Mon Aug 17, 2015 8:29 pm

Hi MauriceAndre,
filter items of tSource with tSearch into tResult
Just plain old

Code: Select all

filter tSource with tSearch
tSource will contain what's left.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

MauriceAndre
Posts: 9
Joined: Fri Aug 17, 2012 12:32 am

Re: filter issues

Post by MauriceAndre » Mon Aug 17, 2015 8:29 pm

Example card:
fld "searchFrequency" contains "Explosion";
table field above it named "wordFreq";
blue button next to it contains script:

Code: Select all

on mouseUp
   set the itemdel to cr
   
   put the text of fld "searchFrequency" into tSearch
   put the text of fld "WordFreq" into tSource
   
   filter items of tSource with tSearch into tResult
   put tResult into fld "wordFreq"
end mouseUp
Attachments
Screenshot.png

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: filter issues

Post by Simon » Mon Aug 17, 2015 8:35 pm

Wow, when English isn't your mother tongue liveCode does seem much more difficult.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: filter issues

Post by Simon » Mon Aug 17, 2015 9:58 pm

I should add filter works on lines so that "item cr" isn't needed.

Code: Select all

put "the cat in the hat" &cr& "the dog in a bog" &cr& "the fish in a dish" into tVAr
filter tVar with "*dog*"
will give you the second line in tVar.

Simon
Edit; ohhh remember to use the wild cards *.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

MauriceAndre
Posts: 9
Joined: Fri Aug 17, 2012 12:32 am

Re: filter issues

Post by MauriceAndre » Tue Aug 18, 2015 12:34 am

Nah! Livecode is pure poetry... Just flies on those English wings! :mrgreen:

And thanks for that last input - the wildcard did it! Genius! Works!!!

MauriceAndre
Posts: 9
Joined: Fri Aug 17, 2012 12:32 am

Re: filter issues

Post by MauriceAndre » Tue Aug 18, 2015 12:36 am

wildcards, I should add - so I craddled my search term in two of them:

"*" &tSearch & "*"

... and indeed no "items" specified. Works on tSource Var as such.

Post Reply