3

I'm trying to use LiveCode to clean up some contact data. I have two lists:

  • SourceList: a list of tab-delimited contact records in a LiveCode table field;
  • FlagList: a list of strings, such as 'test' that I want to check for within the SourceList.

Ideally, I want to highlight 'hits' in both the FlagList rows and the matching characters in the items in the rows of the SourceList, but I'm struggling with errors on my first pass. On loading the SourceList from file, I'm trying to set the colour of any FlagList field rows that are found in the SourceList.

Here's the script on the 'Load SourceList' button...

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

I think I'm making a basic error, so grateful for any guidance.

Mark
  • 2,380
  • 11
  • 29
  • 49

1 Answers1

0

The problem is that f is a string, not a chunk reference or a control reference. You need to add a counter to your repeat loop and write a correct reference, like this:

   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

This will remove the error from the script. I didn't check if it actually works now (I can't see if all control references are correct, for instance).

Mark
  • 2,380
  • 11
  • 29
  • 49
  • 1
    Brilliant! Thanks Mark - that works a treat. Thanks for the clarification that 'f' becomes just a variable in this context. I think can see how to build out from this now. – Keith Clarke Jul 14 '13 at 15:16
  • And if you like the answer, you can also press the triangle that points upwards ;-) – Mark Jul 14 '13 at 15:23
  • 1
    Oh, to have a high enough reputation to be able to promote useful answers! ;-) – Keith Clarke Jul 14 '13 at 16:29
  • Or to re-open LiveCode questions that aren't understood and hence closed by people on Stackoverflow who have to clue about LiveCode. – Mark Jul 14 '13 at 16:37