3

我正在尝试使用 LiveCode 来清理一些联系人数据。我有两个清单:

  • SourceList:LiveCode 表字段中制表符分隔的联系人记录列表;
  • FlagList:我想在 SourceList 中检查的字符串列表,例如“test”。

理想情况下,我想在 FlagList 行和 SourceList 行中的项目中突出显示“命中”,但我在第一次通过时遇到了错误。在从文件加载 SourceList 时,我试图设置在 SourceList 中找到的任何 FlagList 字段行的颜色。

这是“加载源列表”按钮上的脚本...

on mouseUp
  answer file "Select text file to Clean" with type "txt"
  if it <> "" then
    put empty into field "Source"
    put it into field "SourceFile"
    put it into theFilePath
    put URL ("file:" & theFilePath) into field "SourceList"
    repeat for each line f in field "FlagList"
      repeat for each line l in field "SourceList"
        repeat for each item i in l
            if i contains f then set the foregroundColor of f to "red"
        end repeat
      end repeat
    end repeat
  else     
    --no file was selected, or cancel was pressed
    beep
  end if
end mouseUp

我想我犯了一个基本错误,非常感谢任何指导。

4

1 回答 1

0

问题是 f 是一个字符串,而不是块引用或控件引用。您需要在重复循环中添加一个计数器并编写正确的引用,如下所示:

   put 0 into myCounter
   repeat for each line f in field "FlagList"
      add 1 to myCounter
      repeat for each line l in field "SourceList"
         repeat for each item i in l
            if i contains f then
               set the foregroundColor of line myCounter of field "FlagList" to "red"
               exit repeat
            end if
         end repeat
      end repeat
   end repeat

这将从脚本中删除错误。我没有检查它现在是否真的有效(例如,我看不到所有控件引用是否正确)。

于 2013-07-14T14:56:52.443 回答