Page 1 of 1

cr after every 6th line

Posted: Fri Oct 10, 2014 12:46 am
by KennyR
Hello everyone once again. I am back after some time off and having a brain fart. I can't figure out how to put a carriage return after every 6th line in a text field. So simply, I have a ton of lines in a text field and need to separate the data with a cr after every six lines. Thanks for help!
Kenny

PS. I have been trying a repeat loop with no success, so if someone has an idea using a repeat loop it would be greatly appreciated.

Re: cr after every 6th line

Posted: Fri Oct 10, 2014 1:46 am
by Simon
Hey Kenny where you been?
repeat for each line tLine in tMyBigText
add 1 to x
put tLine & cr after tMySplitText
if x = 6 then
put cr after tMySplitText
put 0 into x
end if
end repeat

tMySplitText will have your new text file. :)

Simon
edit: put the fld into tMyBigText first (speed man speed!)

Re: cr after every 6th line

Posted: Fri Oct 10, 2014 2:43 am
by KennyR
SIMON! Hey man...Well I struck it rich with one of my applications and have been living on an enchanted island with supermodels of course! But back to reality...Got sick of coding and took a little vacation from myself... I tend to do this and then catch the fever again...sooo here we go! Thanks for the help my friend...be talking with you soon!
Kenny

Re: cr after every 6th line

Posted: Fri Oct 10, 2014 3:52 am
by dunbarx
Hi.

Simon's way is a good way. How about this as well. I only mention it because it is odd in its way:

Code: Select all

on mouseUp
   repeat with y = 1 to the number of lines of yourData
      if y mod 7= 0 then put return before line y of yourData
   end repeat
end mouseUp
Do you see why the "ordinary" way does not work?:

Code: Select all

on mouseUp
   repeat with y = 1 to the number of lines of yourData
      if y mod 6= 0 then put return after line y of yourData
   end repeat
end mouseUp
Craig Newman

Re: cr after every 6th line

Posted: Fri Oct 10, 2014 3:56 am
by KennyR
I had to modify the code a bit to obtain the results I wanted, but your post put me in the right direction. I want to share with anyone who wants to know...thanks again Simon...

Code: Select all

local tMyBigText, tMySplitText
on mouseUp
   repeat with x=1 to the number of grps on this cd  --I have multiple groups on a card with multiple fields in that group
      repeat with y=1 to the number of flds in grp x  --Step through each group
         put fld y  of grp x & cr after fld "reportField" cd "Report"  --Put each field of each group in the report field
      end repeat
   end repeat
   
--This is where you helped me sort the text and break it up
   put fld "reportField" cd "Report" into tMyBigText
   put 0 into x
   repeat for each line tLine in tMyBigText
      add 1 to x
      put x into fld "counter"
put tLine & cr after tMySplitText
if x >= 6 then --For some reason it would not break the text blocks up unless I changed this to ">=" weird..
put  cr after tMySplitText
put 0 into x
else
end if
end repeat
put empty into tMyBigText
put tMySplitText into fld "reportField" cd "Report"
put empty into tMySplitText
go cd "Report"
   end mouseUp

Re: cr after every 6th line

Posted: Fri Oct 10, 2014 4:03 am
by KennyR
Hi Craig,
So I have to admit, I had to look up "Mod" in the dictionary to understand what you were getting at. If I understand it correctly and how you used it, its simply limiting the number of lines to be evaluated? I am still a little confused on "mod 6=0" though...obviously 6 is the ceiling but what is the "0"?

Re: cr after every 6th line

Posted: Fri Oct 10, 2014 7:59 am
by SparkOut
Mod means give the remainder after dividing. In this case there is a test to see if 0 is what's leftover after dividing y by 6. If 0 then the value was a multiple of 6, therefore (you'd think) it was time to insert a space.
That's not what Craig was on about though.

If inserting a space after every 6th line seems right but actually doesn't work (try it) can you see why adding a space before every 7th line would?

(Up to a point)

There is another caveat (to do with the last part of the data, after the final insert - in fact what should be the penultimate insert - unless you flukily have a data list that is a number of lines divisible by 6)

Re: cr after every 6th line

Posted: Fri Oct 10, 2014 10:20 am
by SparkOut
So here is my take in a few lines

Code: Select all

   repeat with i = the number of lines of tD - (the number of lines of tD mod 6) to 6 step -6
      put cr after line i of tD
   end repeat
 
Write back after examining the above posts and let us know if you can see why things need to work bottom up not top down, and how the start (or end) value matters when operating on a list that affects the index.

Re: cr after every 6th line

Posted: Fri Oct 10, 2014 2:03 pm
by dunbarx
Hi.

What Sparkout said. Try a few of the following:

answer 8 mod 6
answer 11 mod 6
answer 12 mod 6
answer 13 mod 6

The integer remainder is returned in each instance, not by dividing in the ordinary way, but by extracting integral "chunks" of the mod parameter from the argument. Look up its cousin, the "div" operator.

answer 8 div 6
answer 11 div 6
answer 12 div 6
answer 13 div 6

Now think about someday needing to know this:

answer 42578 div 24 && 42578 mod 24

Craig

Re: cr after every 6th line

Posted: Fri Oct 10, 2014 2:38 pm
by Simon
KENT-MOORE J-42578 STEERING WHEEL PULLER LEGS (J42578)???? :)

Simon

Re: cr after every 6th line

Posted: Fri Oct 10, 2014 2:49 pm
by Thierry
dunbarx wrote: Now think about someday needing to know this:

answer 42578 div 24 && 42578 mod 24
Sorry, can't think of any day... :roll:

Thierry

Re: cr after every 6th line

Posted: Fri Oct 10, 2014 3:12 pm
by dunbarx
Now think about someday needing to know this:

answer 42578 div 24 && 42578 mod 24
Sorry, Typo. I mean 42579

Craig

Re: cr after every 6th line

Posted: Sat Oct 11, 2014 10:31 pm
by [-hh]
1 You all together, what a chance.
2 Could you please give a hint to the solution?
3 Meanwhile a less difficult question:
4 hand div clock = 2
5 hand mod clock = 0
6 What's the time?

(Hint: watch is 14)

Re: cr after every 6th line

Posted: Sun Oct 12, 2014 2:53 am
by dunbarx
Hermann.

We played around with something like this last year, right?

I wanted to know what the constants in LC had as associated values, so I did this:

Code: Select all

on mouseUp
   put the constantnames into tnames
   repeat with y = 1 to the number of lines of tnames
        get line y of tNames
        repeat with u = 1 to 99
                      do "if" && it && "=" && u && "then put it && u into line u of accum"
         end repeat
      end repeat
      
      repeat with y = 1 to the number of lines of tnames
         if line y of accum = ""  then put line y of tNames  && "--" into line y of accum
      end repeat
   put accum into fld 1
end mouseUp
Anyway most constants do not seem to have values associated with them. Anyone know why? Or if there is a reason at all?

Craig

Re: cr after every 6th line

Posted: Sun Oct 12, 2014 4:47 am
by [-hh]
Craig wrote:Anyway most constants do not seem to have values associated with them.
I'll try to presume the other way:
When a constant has a value it is probably the (historical) ID of a "resource".
Currently I use an emulated HyperCard on Raspberry Pi and "ResEdit" shows there "CURS" with names and IDs for cursors (eventually a 16x16 bitmap) "hand", "plus" and so on.

By the way: The solution is 20 past two o'clock pm.
[Because watch=clock we have clock is 14 and thus hand is 28.
(Or you know from your script or a dictionary entry directly that hand is 28).
But 28 mod 24 = 4, so one hand is at 4 and the clock is at 14 mod 12 = 2.
That is 14:20 or 20 past two o'clock pm.]