Page 1 of 1
filter issues
Posted: Mon Aug 17, 2015 6:37 pm
by MauriceAndre
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
Re: filter issues
Posted: Mon Aug 17, 2015 6:56 pm
by Simon
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
Re: filter issues
Posted: Mon Aug 17, 2015 6:58 pm
by FourthWorld
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"
Re: filter issues
Posted: Mon Aug 17, 2015 7:11 pm
by dunbarx
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
Re: filter issues
Posted: Mon Aug 17, 2015 8:14 pm
by MauriceAndre
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.
Re: filter issues
Posted: Mon Aug 17, 2015 8:29 pm
by Simon
Hi MauriceAndre,
filter items of tSource with tSearch into tResult
Just plain old
tSource will contain what's left.
Simon
Re: filter issues
Posted: Mon Aug 17, 2015 8:29 pm
by MauriceAndre
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
Re: filter issues
Posted: Mon Aug 17, 2015 8:35 pm
by Simon
Wow, when English isn't your mother tongue liveCode does seem much more difficult.
Simon
Re: filter issues
Posted: Mon Aug 17, 2015 9:58 pm
by Simon
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 *.
Re: filter issues
Posted: Tue Aug 18, 2015 12:34 am
by MauriceAndre
Nah! Livecode is pure poetry... Just flies on those English wings!
And thanks for that last input - the wildcard did it! Genius! Works!!!
Re: filter issues
Posted: Tue Aug 18, 2015 12:36 am
by MauriceAndre
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.