empty line, stepconstruction
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
empty line, stepconstruction
1. What's the trick to remove an empty line in a field "index"; f.i:
John
Pete
George
Johanna
I tried something like "remove empty lines of field "index": nope!
2.
I am looking for a step-construction as I was accustomed to:
step i from 1 to 50
readline= textline i of field "foo"
if readline = selectedtext
do something
end if
end step
I tried repeat, but the dictionary confuses me.
John
Pete
George
Johanna
I tried something like "remove empty lines of field "index": nope!
2.
I am looking for a step-construction as I was accustomed to:
step i from 1 to 50
readline= textline i of field "foo"
if readline = selectedtext
do something
end if
end step
I tried repeat, but the dictionary confuses me.
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: empty line, stepconstruction
Would something like this work?
Code: Select all
on mouseUp
put the number of lines in fld 1 into tVar
repeat with i = 1 to tvar
if line i of fld 1 is empty then delete line i of fld 1
end repeat
end mouseUp
Re: empty line, stepconstruction
Code: Select all
repeat with i = the number of lines in fld "foo" down to 1
if line i of fld "foo" is empty then delete line i of fld "foo"
end repeat
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: empty line, stepconstruction
Hi Magice,
Would you mind explaining what the "down to 1" part of your script is doing? I tried almost the exact script without "down to 1" and it didn't work, which is why I put it into a variable first.
Thanks,
Sefro
Would you mind explaining what the "down to 1" part of your script is doing? I tried almost the exact script without "down to 1" and it didn't work, which is why I put it into a variable first.
Thanks,
Sefro
Re: empty line, stepconstruction
When you delete lines, the number of the next line is reduced by 1, or becomes the line you just deleted. Since the incrementation (i) increases with each iteration, starting at the top and working down will cause the next line to be skipped. When you start at the bottom and work up, the next line doesn't change numbers.
Last edited by magice on Wed May 14, 2014 9:09 pm, edited 1 time in total.
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: empty line, stepconstruction
Makes perfect sense. Thanks! 

Re: empty line, stepconstruction
magice has the right approach to a loop which affects the index. However, for an alternative to use in this context:
Code: Select all
filter field "index" without empty
Re: empty line, stepconstruction
Magice,Would you mind explaining what the "down to 1" part of your script is doing? I tried almost the exact script without "down to 1" and it didn't work, which is why I put it into a variable first.
The string down to 1 was not out of my brains, I don't know where it is coming from.
The trick to start deleting from bottom to top was well known to me: you are quite right with that.
I will try both scripts you send, especially this one:
repeat with i = the number of lines in fld "foo" down to 1
if line i of fld "foo" is empty then delete line i of fld "foo"
end repeat
Thank you
Rob
Re: empty line, stepconstruction
Hello Sparkout,
I started my exercise with your script, being the shortest: filter field "index" without empty
and it is perfect.
Rob
I started my exercise with your script, being the shortest: filter field "index" without empty
and it is perfect.
Rob