cr after every 6th line
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
cr after every 6th line
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.
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.
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: cr after every 6th line
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!)
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!
Re: cr after every 6th line
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
Kenny
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: cr after every 6th line
Hi.
Simon's way is a good way. How about this as well. I only mention it because it is odd in its way:
Do you see why the "ordinary" way does not work?:
Craig Newman
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
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
Re: cr after every 6th line
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
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"?
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
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)
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
So here is my take in a few lines
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.
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
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: cr after every 6th line
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
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
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: cr after every 6th line
KENT-MOORE J-42578 STEERING WHEEL PULLER LEGS (J42578)????
Simon
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: cr after every 6th line
Sorry, can't think of any day...dunbarx wrote: Now think about someday needing to know this:
answer 42578 div 24 && 42578 mod 24
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: cr after every 6th line
Sorry, Typo. I mean 42579Now think about someday needing to know this:
answer 42578 div 24 && 42578 mod 24
Craig
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: cr after every 6th line
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)
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
-
- VIP Livecode Opensource Backer
- Posts: 9709
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: cr after every 6th line
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:
Anyway most constants do not seem to have values associated with them. Anyone know why? Or if there is a reason at all?
Craig
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
Craig
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: cr after every 6th line
I'll try to presume the other way:Craig wrote:Anyway most constants do not seem to have values associated with them.
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