2013-07-14 16 views
3

我正在嘗試使用LiveCode清理一些聯繫人數據。我有兩個列表:LiveCode在表格字段中查找列表項

  • SOURCELIST:在一個LiveCode表字段製表符分隔的聯繫人記錄列表;
  • FlagList:我想檢查SourceList中的字符串列表,例如'test'。

理想情況下,我想突出顯示FlagList行中的'hits'和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 

我覺得我在做一個基本的錯誤,所以感謝任何指導。

回答

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 

這將從腳本中刪除錯誤。我沒有檢查它是否真的有效(例如,我看不到所有的控件引用都是正確的)。

+1

太棒了!感謝馬克 - 這是一種享受。謝謝澄清,'f'在這種情況下變成了一個變量。我認爲現在可以看到如何從中建立。 –

+0

如果你喜歡答案,你也可以按向上指向的三角形;-) – Mark

+1

哦,要有足夠高的聲譽,能夠促進有用的答案! ;-) –