At 1:13 PM -0400 5/2/01, Gene Fritzinger wrote:
>I have a field member which has 1500+ lines of text at varying
>lengths. I'm trying to write a repeat loop that will go through
>each line, count the characters and add one space at the beginning
>of the line and then x number of spaces at the end of the line so
>all lines have 100 characters. Although I've sucessfully writen
>other repeat loops in the past, I'm getting confused with this one
>(still relatively new to lingo). Below, is where I'm at with the
>code. But this is adding 1500+ lines of nothing but spaces. Could
>someone please help me understand way this is not working? Please
>forgive my newbeeness.
>
>on makeFieldLengths100
> global z, x, theLine, numberOfSpaces, howManySpaces, theCharacter,
>theNewLine
> z = member("AccountMastText").line.count--the number of lines in the field
> repeat with i = 1 to z--do all lines
> theLine = line i of field "AccountMastText"
> put " " before theLine--add a space before theLine
> x = the number of chars in theLine--number of chars in theLine
> numberOfSpaces = 100 - x--number of spaces to add
> theCharacter = " "--a space
> repeat with m = 1 to numberOfSpaces--number of spaces to add
> put theCharacter &RETURN after theLine
> end repeat
>
> end repeat
>
>end makeFieldLengths100
>
Just looking at your code, I'm guessing that the problem is in the:
repeat with m = 1 to numberOfSpaces
put theCharacter & return after theLine
Here you are adding a space and a return every time. I think you
only want to add a space every time in this loop, and a return when
you are done.
A couple of comments. Not trying to beat you up, but please take
these suggestions as trying to help you with your "newbeeness".
- there is no need to have your variables be globals (unless you are
want to look at them in the message window).
- I can suggest an alternative approach. Copy the starting text
into a local variable, create a new local variable, then put the text
back in.
- use more meaningful variable names than x, y, and z.
- for efficiency reasons, there is no need to keep re-assigning
theCharacter = " " inside your loop. In fact, the keyword SPACE is
already defined for you.
So, here's a different set of code (completely untested, but based on
your algorithm):
on makeFieldLengths100
theTextIn = member("AccountMastText").text
nLines = theTextIn.line.count
theTextOut = ""
repeat with thisLineNum = 1 to nLines
thisLineIn = line thisLineNum of theTextIn
nChars = the number of chars in thisLineIn
nSpacesNeeded = 99 - nChars
thisLineOut = SPACE & thisLineIn
repeat with i = 1 to nSpacesNeeded
put SPACE after thisLineOut
end repeat
put thisLineOut & RETURN after theTextOut
end repeat
member("AccountMastText").text = theTextOut
end
Good luck,
Irv
--
Lingo / Director / Shockwave development for all occasions.
(Home-made Lingo cooked up fresh every day just for you.)
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]