Issue while filtering a received string

Want to move your code and projects to LiveCode but don't know where to start?

Moderators: FourthWorld, heatherlaine, Klaus, robinmiller

Post Reply
fgraux
Posts: 5
Joined: Wed Jun 12, 2019 10:50 am

Issue while filtering a received string

Post by fgraux » Wed Jun 12, 2019 11:18 am

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Issue while filtering a received string

Post by jacque » Wed Jun 12, 2019 5:36 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

fgraux
Posts: 5
Joined: Wed Jun 12, 2019 10:50 am

Re: Issue while filtering a received string

Post by fgraux » Thu Jun 13, 2019 8:55 am

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Issue while filtering a received string

Post by jacque » Thu Jun 13, 2019 8:11 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

fgraux
Posts: 5
Joined: Wed Jun 12, 2019 10:50 am

Re: Issue while filtering a received string

Post by fgraux » Fri Jun 14, 2019 8:07 am

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

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am
Location: Earth, Except when i Jump

Re: Issue while filtering a received string

Post by sphere » Fri Jun 14, 2019 12:47 pm

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)

fgraux
Posts: 5
Joined: Wed Jun 12, 2019 10:50 am

Re: Issue while filtering a received string

Post by fgraux » Fri Jun 14, 2019 6:09 pm

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

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7210
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Issue while filtering a received string

Post by jacque » Fri Jun 14, 2019 7:21 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

fgraux
Posts: 5
Joined: Wed Jun 12, 2019 10:50 am

Re: Issue while filtering a received string

Post by fgraux » Mon Jun 17, 2019 11:26 am

Thank you jacque
it's perfectly working
best

Post Reply

Return to “Converting to LiveCode”