4 Replies Latest reply on Jul 5, 2007 7:07 PM by James Newton, ACP

    "do" command problem

    KMELBone
      I am trying to execute a simple "do" command in a loop.

      repeat with flagCount = numberLayers down to 1
      toExecute = "layer" & flagCount & "Flag = 1"
      do (toExecute)
      end repeat

      I put in a breakpoint, and the 'toExecute' variable has the correct string in each iteration, but for some reason no flag is ever set to 1. It is almost as if it is ignoring the whole line.

      Any help would be appreciated. Thanks!
        • 1. Re: "do" command problem
          Level 7
          > I am trying to execute a simple "do" command in a loop.
          >
          > repeat with flagCount = numberLayers down to 1
          > toExecute = "layer" & flagCount & "Flag = 1"
          > do (toExecute)
          > end repeat
          >
          > I put in a breakpoint, and the 'toExecute' variable has the correct string in
          > each iteration, but for some reason no flag is ever set to 1. It is almost as
          > if it is ignoring the whole line.

          Use of the "do" command almost always screams "there's a better way to
          achieve this". In the above case a linear or property list.

          That being said, perhaps you need to elevate your flags to _global:
          -- <snip>
          toExecute = "_global.layer" & flagCount & "Flag = 1"
          -- <etc.>
          • 2. Re: &quot;do&quot; command problem
            KMELBone Level 1
            The reason I was trying to write it in a loop was that the number of layers will be different every time (and won't be known until the program loads up and reads the input files)....

            Is there a better way to do this that I'm just not thinking of?
            • 3. Re: &quot;do&quot; command problem
              Level 7
              > Is there a better way to do this that I'm just not thinking of?

              Perhaps. You could maintain a (global?) property list and add
              propName:value entries to it as needed. But I don't know your specific
              implementation or requirements. Can you put what you're doing into context?
              • 4. Re: &quot;do&quot; command problem
                James Newton, ACP Level 3
                You could create a property list, and set the values of the properties to 0 or 1:

                if ilk(gFlags) <> #propList then
                gFlags = [:]
                gFlags.sort()
                end if

                i = numberLayers
                repeat with i = 1 to numberLayers
                gFlags.setaProp(i, TRUE)
                end if

                The above code assumes that gFlags and numberLayers are declared as globals or properties, as appropriate.

                To check if the flag corresponding to layer 1 is set:

                if gFlags.getaProp(1) then
                -- do stuff
                end if

                If the number of flags is arbitrary, you may need to check that the layer number is not greater than the number of flags.

                The example uses a property list, but a linear list would probably work just as well. You'd need to use setAt() and getAt() instead of setaProp() and getaProp(). Alternatively, you could use more meaningful property names than I have done.