LiveCode在表字段中查找列表项

时间:2013-07-14 13:49:08

标签: string text contains livecode

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

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

理想情况下,我想强调FlagList行中的'hits'和SourceList行中项目中的匹配字符,但我在第一次传递时遇到错误。在从文件加载SourceList时,我正在尝试设置在SourceList中找到的任何FlagList字段行的颜色。

这是'Load SourceList'按钮上的脚本......

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

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

1 个答案:

答案 0 :(得分: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

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