我正在尝试使用LiveCode清理一些联系数据。我有两个清单:
SourceList:LiveCode表字段中以制表符分隔的联系人记录的列表;
FlagList:字符串列表,例如我要在SourceList中检查的“测试”。
理想情况下,我想在FlagList行和SourceList行中的项目中突出显示“命中”,但是我在第一次通过时就遇到了错误。从文件加载SourceList时,我试图设置在SourceList中找到的任何FlagList字段行的颜色。
这是“加载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
我想我犯了一个基本错误,非常感谢任何指导。
最佳答案
问题是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
这将从脚本中删除错误。我没有检查它是否现在可以正常工作(例如,我看不到所有控件引用是否正确)。