Page 1 of 1
Issue while filtering a received string
Posted: Wed Jun 12, 2019 11:18 am
by fgraux
Hi there
I receive a string from a distant server containing a list of files(including their folder), aka :
Folder1/File1
Folder1/File2
Folder2/File3
etc
I want put this into a dataGrid and be able to filter those within folder.
I manage to emulate a menu button to choose the folder
with this code :
put textString into the field "tempList"
replace "/" with " " in the field "tempList"
repeat for each line tLine in the field "tempList"
Put the first word of tLine & format("\r\n") after foldText
end repeat
split foldText by return and return
combine foldText by return and empty
delete the last char of foldText
put foldText into the button "templatefold"
set the ListFold of the button "templatefold" to foldText
(I created a custom key "ListFold" onto the button)
But when I want to filter using the option button, only the last folder returns the right result, the others return nothing, I tried lots of methods but all failed, here is my last button script :
on mouseUp
put line (the menuHistory of me) of the ListFold of me into tSelectedLine
put tSelectedLine & format("*") into tSelectL
filter lines of field "tempList" with tSelectL into theFilteredList
put theFilteredList into the field "test"
end mouseUp
Does someone faced such an issue ? Please let me know. Thx
Re: Issue while filtering a received string
Posted: Wed Jun 12, 2019 5:36 pm
by jacque
Try this:
Code: Select all
put textString into tList
split tList by cr and slash
put the keys of tList into button "templatefold"
You don't need to use "the" when referring to object names, BTW.
For the option button:
Code: Select all
put the text of line (the menuhistory of me) of me into tFolder
filter lines of field "templist" with tFolder
I didn't test, so you may need to adjust the script.
Re: Issue while filtering a received string
Posted: Thu Jun 13, 2019 8:55 am
by fgraux
Hi jacque
thanks for your answer.
I tried your solution :
the first code nicely populates the button.
But the second code (option button one) sends to an error :
Code: Select all
button "templatefold": execution error at line 5 (Object: object does not have this property), char 17
Did I miss something ?
thanks again
Re: Issue while filtering a received string
Posted: Thu Jun 13, 2019 8:11 pm
by jacque
Post the whole button script so we can see what's happening. I only provided a couple of lines, so something else is going on.
Re: Issue while filtering a received string
Posted: Fri Jun 14, 2019 8:07 am
by fgraux
Hi Jacque
here is the retrieved string:
Code: Select all
OLD/FRAMESSSS
OLD/NTSC-TEST-30
OLD/NTSC-TEST-60
OLD/PHONE
OLD/SCORE_STARS2
TITRE/1MANDARIN
TITRE/BASIC2_A
TITRE/COMINGUPNEXT2FIELDS
XTEMPLATE/INDEX
SCORE/1SCORE_STARS2
SCORE/12CHAMPS
SCORE/8CHAMPS
SCORE/24CHAMPS
HTML_TEMPLATE/TEMPLATE2
HTML_TEMPLATE/TEMPLATE
ESPORT-TEMPLATES-MASTER/01_INTERVIEW
ESPORT-TEMPLATES-MASTER/00_TEMPLATE
ESPORT-TEMPLATES-MASTER/02_CASTERS
ESPORT-TEMPLATES-MASTER/10_BRACKET
ESPORT-TEMPLATES-MASTER/11_ADROTATE
ESPORT-TEMPLATES-MASTER/12_TIMETABLE
ESPORT-TEMPLATES-MASTER/17_HSMAINOKSET
ESPORT-TEMPLATES-MASTER/13_GROUP
ESPORT-TEMPLATES-MASTER/20_CLOCK
ESPORT-TEMPLATES-MASTER/18_HSINGAME
ESPORT-TEMPLATES-MASTER/19_GAMERS
ESPORT-TEMPLATES-MASTER/50_TITLESAFE
ESPORT-TEMPLATES-MASTER/TESTFRAME
here is the script of the card:
Code: Select all
put textString into field "tempList"
replace "/" with " " in field "tempList"
repeat for each line tLine in field "tempList"
if the first word of tLine ="SCORE" or the first word of tLine = "200" or the first word of tLine = "202" or the first word of tLine = "" or the first word of tLine = "403" or the first word of tLine = "404"
then
put tLine into tDump
else
Put the first word of tLine & format("\r\n") after foldText
delete the first word of tLine
Put tLine & format("\r\n") after gridText
end if
end repeat
split foldText by cr and slash
put the keys of foldText into button "templatefold"
set the dgText of group gMedia to gridText
and finally the script of the button:
Code: Select all
on mouseUp
put the text of line (the menuhistory of me) of me into tFolder
filter lines of field "templist" with tFolder into field "test"
end mouseUp
thanks
Re: Issue while filtering a received string
Posted: Fri Jun 14, 2019 12:47 pm
by sphere
you could set the itemdelimiter to "/"
put item 1 of line tLine into a variable
if the variable is "SCORE"
put item 2 of line tLine into another variable (which is the rest of your line)
Re: Issue while filtering a received string
Posted: Fri Jun 14, 2019 6:09 pm
by fgraux
Thank you Sphere
I'm a new LC user and didn't know the itemDelimiter which is quite usefull.
However, my problem remains the same in the final part :
I early succeed to build the menu button dynamically (but updated to follow your method).
The things is that it still refuses to filter my gridtext, except for the last choice of my button and I can't explain why...
If a genious idea comes to anyone, please let me know.
Thanks
Re: Issue while filtering a received string
Posted: Fri Jun 14, 2019 7:21 pm
by jacque
Accessing fields is one of the slowest things in LC so it is always better to move the text to a variable, process it, and then put it back. But since you're just testing I've left most of the field access the way you have it now.
For the card script (I named the handler, since you didn't include that, but use whatever method you use instead):
Code: Select all
on processText
put fld 1 into textString
put textString into field "tempList"
replace "/" with " " in textString
put "SCORE,200,202,403,404" into tRejects
repeat for each line tLine in textString
if the first word of tLine <> "" and the first word of tLine is not among the items of tRejects then
put the first word of tLine & cr after foldText
delete the first word of tLine
put tLine & cr after gridText
end if
end repeat
split foldText by cr and slash
put the keys of foldText into button "templatefold"
set the dgText of group gMedia to gridText
end processText
You'll probably see some new ideas in there, mainly the "among" keyword which makes it easier to access parts of a list of things instead of writing each one out in the script.
For the option button, use the "label" property instead of the menuhistory. I also gave you an incomplete filter command which needed an asterisk:
Code: Select all
on mouseUp
put the label of me into tFolder
filter lines of field "templist" with (tFolder & "*") into field "test"
end mouseUp
The format command is rarely needed. What you're looking for is the constant "cr" which indicates a carriage return. CR will match the line ending of the current OS, so you don't need to worry whether you need a return, a linefeed, or a return-linefeed. It's all automatic.
Re: Issue while filtering a received string
Posted: Mon Jun 17, 2019 11:26 am
by fgraux
Thank you jacque
it's perfectly working
best