Page 1 of 1

empty line, stepconstruction

Posted: Wed May 14, 2014 8:34 pm
by robm80
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.

Re: empty line, stepconstruction

Posted: Wed May 14, 2014 8:52 pm
by sefrojones
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

Posted: Wed May 14, 2014 8:53 pm
by magice

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
 

Re: empty line, stepconstruction

Posted: Wed May 14, 2014 8:57 pm
by sefrojones
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

Re: empty line, stepconstruction

Posted: Wed May 14, 2014 9:05 pm
by magice
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.

Re: empty line, stepconstruction

Posted: Wed May 14, 2014 9:07 pm
by sefrojones
Makes perfect sense. Thanks! :D

Re: empty line, stepconstruction

Posted: Wed May 14, 2014 9:08 pm
by SparkOut
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

Posted: Thu May 15, 2014 5:22 am
by robm80
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.
Magice,
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

Posted: Thu May 15, 2014 5:27 am
by robm80
Hello Sparkout,
I started my exercise with your script, being the shortest: filter field "index" without empty
and it is perfect.
Rob