[Date Prev][Date Next][Thread Prev][Thread Next]
[Author Index]
[Date Index]
[Thread Index]
[SQR-USERS Info]
[SQRUG Home Page]
Re: Wrapping of a substring
- Subject: Re: Wrapping of a substring
- From: Bob Buford <bbuford@CCCI.ORG>
- Date: Fri, 23 Oct 1998 11:58:51 -0400
Christy,
Wayne and Tony are right. I went a little more elaborate because I wanted to handle carriage returns, etc. I put the code inside a procedure so I could call it from a while loop elsewhere. Next step would be to put it in an SQC (haven't needed to yet). Anyway, here is my code, preceded by several inits:
INITS
Let #LineLength = 75
Let $crlf = chr(10) || chr(12)
Let #LineLimit = 25 !25 lines max accepted.
CALLING CODE
move 1 to #Line ! $Text is the message to be parsed
while $Text > '' !loop for <= 25 lines
do GetLine($Text, $Output, $Text) !make a new line
write 1 from $Output
if #line = #LineLimit !break at the max lines limit
break
else
add 1 to #Line !increment line counter
end-if
end-while
PARSING CODE:
begin-procedure GetLine($Input,:$Output,:$Remain)
let #CRLF = instr($Input,$_crlf,1)
let #Len = length($Input)
if #CRLF >0 and #CRLF <= #_LineLength !check for CRLFs
let #CRLF1 = #CRLF - 1
let #CRLF2 = #CRLF + 2
let $Output = substr($Input,1,#CRLF1)
let $Remain = substr($Input,#CRLF2,#Len)
else !process for text / spaces
if length($input) <= #_LineLength !does remainder fit in line
Let $Output = $Input
Let $Remain = ''
else !find space w/in linelength
Let #Pos = #_LineLength
while #Pos > 0 !loop down from line length
Let $TestChar = substr($Input,#Pos,1)
if $TestChar = chr(32) !test for right-most space
break ! found it, break from loop
else
Add -1 to #Pos ! not space, decrement
end-if
end-while
if #Pos = 0 and $Input > '' !this shouldn't happen, but if no
Let #Pos = #_LineLength !spaces, make a full line anyway.
end-if
Let $Output = substr($Input,1,#Pos) !This is the next line
Add 1 to #Pos !Increment #Pos for substr
Let $Remain = substr($Input,#Pos,#Len) !Set the remaining text
end-if
end-if
end-procedure !GetLine
>>> Christy_Zigich <Christy_Zigich@THE-FIRM.NET> 10/16 8:00 PM >>>
Hello to all! I hope that someone can be of some assistance. I am writing
an SQR to create a print, my code to print the variable $comments_2000 is as
follows:
let $COMMENTS_20001 = substr($COMMENTS_2000,1,28)
let $COMMENTS_20002 = substr($COMMENTS_2000,29,250)
graphic () font 3 8
let #pos = 30
print $COMMENTS_20001 (#line, #pos) wrap 28 1 STRIP=<13> ON=<10>
let #length = #comments_2000_length - 28
if #length > 0
add 1 to #line
let #pos = 13
print $COMMENTS_20002 (#line, #pos) wrap 55 5 STRIP=<13> ON=<10>
end-if
if #length < 55
add 1 to #line
else
if #length < 110
add 2 to #line
else
if #length < 165
add 3 to #line
else
if #length < 210
add 4 to #line
else
if #length < 222
add 5 to #line
end-if
end-if
end-if
end-if
end-if
do chart-field-acct
let #pos = 2
print 'CHART FIELD ACCOUNT:' (#line, #pos)
print $chart_acct (#line, 15 )
add 1 to #line
end-procedure !Print-Line-Comments
The client wants the first line of the comment to start at position 30 and
then wrap to the next line starting at position 13.
All of this works, my problem is that the output comments are wrapping in
the middle of words
Example:
(#pos 30) Enter any comments that pert <-- the problem
(#pos 13) ain to Line 1 here. These comments pertain to Line
1. These
comments will print on the PO. The only time
there seems to be a
problem is on the first line: the
$COMMENTS_20001 substr line.
Also, I have no embedded carriage returns.
Thanks for your time,
Christy Zigich
Christy_Zigich@the-firm.net