如何获得正确的行数和类别

时间:2014-03-31 18:08:19

标签: livecode

我有一个堆栈,其中有3个字段可以切换颜色及其相应的复选框。同时切换应该更改变量(gMyCategories)以便计算正确的行数和类别类型。 “全选”按钮工作正常,但通过切换文本字段(短,中,长)来选择和分析每个类别的代码不起作用 - 我没有在显示字段中获得正确的行号和类别: "分类"和"将显示"。 代码在" fldCat" (见堆栈)

    global gAllLines,gMyCategories

on mouseUp
   set the itemDel to tab
   put empty into gMyCategories

   repeat with j = 1 to the number of fields of grp "fldCat"
      if the backgroundcolor of the target is white then
         set the hilite of btn (the short name of the target) of grp "CheckCat" to "true"
         put the short name of the target & tab after gMyCategories
         set  the backgroundcolor of the target to yellow
      else
         set  the backgroundcolor of the target to white
         set the hilite of btn (the short name of the target) of grp "CheckCat" to "false"
      end if
   end repeat

   delete char -1 of gMyCategories  --tab
   put gMyCategories into fld "SelCat"

   local LinesInMyCategories
   repeat for each line i in gAllLines
      if item 3 of i is among the items of gMyCategories then put item 1 of i &tab& item 2 of i & tab & item 3 of i &tab& item 4 of i &cr after LinesInMyCategories  --lines in selected categories
   end repeat
   delete char -1 of LinesInMyCategories  --return

   put the number of lines in LinesInMyCategories into fld "NrOfLines"
   put the number of items in gMyCategories into fld "NrOfCategories"
end mouseUp

我需要纠正什么? 看到这里的堆栈: toggle field selection.zip

keram

1 个答案:

答案 0 :(得分:1)

尝试修改此代码;

global gAllLines,gMyCategories


on mouseUp
   set the itemDel to tab
   put empty into gMyCategories

   # toggle the clicked field
   if the backColor of the target = white then
      set the backColor of the target to yellow
   else
      set the backColor of the target to white
   end if

   # build list of selected
   repeat with j = 1 to the number of fields of grp "fldCat"
      put the short name of field j of grp "fldCat" into tName
      if the backgroundcolor of field j of grp "fldCat" is white then
         set the hilite of btn tName of grp "CheckCat" to false
      else
         put tName & tab after gMyCategories
         set the hilite of btn tName of grp "CheckCat" to true
      end if

   end repeat

   delete char -1 of gMyCategories  --tab
   put gMyCategories into fld "SelCat"


   local LinesInMyCategories
   repeat for each line i in gAllLines
      if item 3 of i is among the items of gMyCategories then put item 1 of i &tab& item 2 of i & tab & item 3 of i &tab& item 4 of i &cr after LinesInMyCategories  --lines in selected categories
   end repeat
   delete char -1 of LinesInMyCategories  --return

   put the number of lines in LinesInMyCategories into fld "NrOfLines"
   put the number of items in gMyCategories into fld "NrOfCategories"
end mouseUp