Question

The stack I made is displaying categorized lines of text. I made a card to select the categories put them into a variable and populate a data grid form but the code for populating the data grid for My Categories does not work:

Here is the code for populating the form:

global gAllLines,gSelectedCategories,gMyCategories  
on mouseUp  
   put empty into gAllLines  
   put fld "alllines" of cd "settings_files" of stack "settingsandfiles" into gAllLines  
   put empty into gMyCategories  

   repeat for each line i in gAllLines  
      if item 2 of i is among the items of gSelectedCategories then put i & cr after gMyCategories  
   end repeat  

   set the dgText of group "mycategories_compact" to gMyCategories  

end mouseUp  

The download link for the stack (best working so far, but still not 100% OK) is:
https://dl.dropboxusercontent.com/u/99863601/Data%20grid%20Form_All%20Lines%20Categories%20Selections3.zip

Please let me know how to fix it.
Thanks in advance.
keram

Was it helpful?

Solution

The problem is you have two different itemDelimiters. Your field "alllines" has tab delimited data while your gSelectedCategories has comma delimited. Try:

global gAllLines,gSelectedCategories,gMyCategories  
on mouseUp  
   put empty into gAllLines  
   put fld "alllines" of cd "settings_files" of stack "settingsandfiles" into gAllLines  

   put empty into gMyCategories

   replace comma with tab in gSelectedCategories
   set the itemDelimiter to tab

   repeat for each line i in gAllLines  
      if item 2 of i is among the items of gSelectedCategories then put i & cr after gMyCategories  
   end repeat  

   set the dgText of group "mycategories_compact" to gMyCategories  
end mouseUp

Edit

I never use dgText so I'm not sure why buy this datagrid seems to not accept dgText["firstLineContainsColumnNames"] any more. So to me the logical solution is to use dgData:

global gAllLines,gSelectedCategories,gMyCategories
on mouseUp

   set the dgData of group "mycategories_compact" to empty
   put empty into gMyCategories
   replace comma with tab in gSelectedCategories
   set the itemDelimiter to tab

   local tIndex = 1,tDataA
   repeat for each line i in gAllLines
      if item 2 of i is among the items of gSelectedCategories then 
         put item 1 of i into tDataA[tIndex]["Text"]
         put item 2 of i into tDataA[tIndex]["Category"]
         add 1 to tIndex
      end if
   end repeat
   set the dgData of group "mycategories_compact" to tDataA

end mouseUp

OTHER TIPS

I have not looked at your stack, but the handler works fine as far as it goes. That is, the global variable "gSelectedCategories" is loaded if one of the checkbox buttons has one of the words you are checking for in its name, What are you not seeing?

Craig Newman

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top