Page 1 of 1

How to get editor to indent on "do 'repeat'..."?

Posted: Wed Oct 09, 2019 2:08 pm
by MichaelBluejay
Code editor doesn't indent the "repeat" if it's executed via a "do":

Code: Select all

put fld manyLines1 into tDebits
put fld manyLines2 into tCredits

repeat for each item debitOrCredit in "tDebits,tCredits"
   do "repeat for each line theLine in" && debitOrCredit
   addToDatabase(item 2 of theLine, item 5 of theLine) -- not indented
   do "end repeat"
end repeat
I presume there's no way to get the code editor to indent properly in this case? If not, then maybe there's a better way to process this data without "do 'repeat...". I'm open to that, I'm not married to "do 'repeat..."

One thing I could do would be to tag each line of each field with some identifier, then combine text of both fields, and then operate on them as a single string. That feels clumsy, though.

Re: How to get editor to indent on "do 'repeat'..."?

Posted: Wed Oct 09, 2019 2:22 pm
by bogs
Ok, I'll bite.

Why use the "do" instead of just nesting the repeats? (not in the IDE at the moment, just an honest question)

Code: Select all

put fld manyLines1 into tDebits
put fld manyLines2 into tCredits

repeat for each item debitOrCredit in "tDebits,tCredits"
   repeat for each line theLine in theItem
      addToDatabase(item 2 of theLine, item 5 of theLine) -- now indented
   end repeat
end repeat

Re: How to get editor to indent on "do 'repeat'..."?

Posted: Wed Oct 09, 2019 2:35 pm
by dunbarx
Michael.

You really must start placing literals in quotes. Trust me. You will be glad you did.

Code: Select all

put fld "manyLines1" into tDebits
There is a preference that sets the SE indent level, from 2 to 5 chars. But it does not go to 0. What I mean is, I have never seen the SE fail to indent. You might try playing with that preference just to see if something changes.

What OS?

Craig

Re: How to get editor to indent on "do 'repeat'..."?

Posted: Wed Oct 09, 2019 2:52 pm
by MichaelBluejay
bogs, I'm afraid that doesn't work because "theLine" doesn't refer to each line in the variable tDebits, it refers to the number of lines in the *string literal* "tDebits". Try this:

Code: Select all

put (a,b,c,d,e,f,g) into tDebits
put (a,b,c,d,e,f,g) into tCredits
replace comma with cr in tDebits
replace comma with cr in tCredits
answer tDebits -- a bunch of lines

repeat for each item debitOrCredit in "tDebits,tCredits"
   repeat for each line theLine in debitOrCredit
      answer theLine -- not a line of data!
   end repeat
end repeat
dunbarx, it's Mac OS X. The thing is, once I put the "repeat" inside a "do", the code editor doesn't see the command as "repeat", it sees it as "do", so it doesn't indent. In fact, if you do that, then you have to put the "end repeat" inside a "do" otherwise you get an error.

I'm rethinking my data structure so I don't have to have multiple repeats. The hardest part of this project isn't the coding (LiveCode syntax is pretty damn easy), it's figuring out how to organize the data.

Re: How to get editor to indent on "do 'repeat'..."?

Posted: Wed Oct 09, 2019 3:02 pm
by bogs
Once I thought about it, I figured out you were trying to get the line to either execute or return a result as if the line were code, however, it doesn't change the structure of what I was thinking, instead, you just move the do to this kind of format (I think) -
...my code from earlier, using do still in a nested repeat structure:

Code: Select all

put fld manyLines1 into tDebits
put fld manyLines2 into tCredits

repeat for each item debitOrCredit in "tDebits,tCredits"
   repeat with x=1 to the number of lines of theItem
      do line x of theItem && {the rest of your code} -- still indented
   end repeat
end repeat