cr after every 6th line

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

cr after every 6th line

Post by KennyR » Fri Oct 10, 2014 12:46 am

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.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: cr after every 6th line

Post by Simon » Fri Oct 10, 2014 1:46 am

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!)
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: cr after every 6th line

Post by KennyR » Fri Oct 10, 2014 2:43 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9709
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: cr after every 6th line

Post by dunbarx » Fri Oct 10, 2014 3:52 am

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

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: cr after every 6th line

Post by KennyR » Fri Oct 10, 2014 3:56 am

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

KennyR
Posts: 256
Joined: Thu Jan 19, 2012 4:25 am

Re: cr after every 6th line

Post by KennyR » Fri Oct 10, 2014 4:03 am

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"?

SparkOut
Posts: 2856
Joined: Sun Sep 23, 2007 4:58 pm

Re: cr after every 6th line

Post by SparkOut » Fri Oct 10, 2014 7:59 am

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)

SparkOut
Posts: 2856
Joined: Sun Sep 23, 2007 4:58 pm

Re: cr after every 6th line

Post by SparkOut » Fri Oct 10, 2014 10:20 am

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9709
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: cr after every 6th line

Post by dunbarx » Fri Oct 10, 2014 2:03 pm

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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: cr after every 6th line

Post by Simon » Fri Oct 10, 2014 2:38 pm

KENT-MOORE J-42578 STEERING WHEEL PULLER LEGS (J42578)???? :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: cr after every 6th line

Post by Thierry » Fri Oct 10, 2014 2:49 pm

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
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9709
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: cr after every 6th line

Post by dunbarx » Fri Oct 10, 2014 3:12 pm

Now think about someday needing to know this:

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

Craig

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: cr after every 6th line

Post by [-hh] » Sat Oct 11, 2014 10:31 pm

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)
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9709
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: cr after every 6th line

Post by dunbarx » Sun Oct 12, 2014 2:53 am

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

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: cr after every 6th line

Post by [-hh] » Sun Oct 12, 2014 4:47 am

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.]
shiftLock happens

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”