Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim memo field 2

Status
Not open for further replies.

JPG77

Programmer
Mar 22, 2002
27
0
0
FR
Hi,

I want to trim all the leading chr(13) or chr(10) at the end of a memo field (before printing).
Alltrim() or trim() has no effect on the chr(13).

strtran() will be a solution but ONLY on the last line.
Is there another function available ?

Jean-Paul
 
Hello Jean-Paul.

>> I want to trim all the leading chr(13) or chr(10) at the end of a memo field (before printing).
Alltrim() or trim() has no effect on the chr(13). <<

Code:
lcMemo = CHRTRAN( lcMemo, CHR(13)+CHR(10), '' )





Marcia G. Akins
 
Thanks Marcia but this will trim chr(13) at the end of the memo field AND INSIDE the memo field. I just want at the end, like TRIM(memo).
I think I have to edit all the memo line and STRTRAN only on the last line.

JPG
 
Hi JPG.

>> I just want at the end, like TRIM(memo). <<

Sorry. I misunderstood :~/

Try this instead:

Code:
lcMemo = ALLTRIM( MyAlias.MyMemoField )
lnLen = LEN( lcMemo ) - 2
lcMemo = LEFT( lcMemo, lnLen )



Marcia G. Akins
 
Marcia,
That assumes there's only a single CHR(13)+CHR(10) at the end of the memo. I've found that users will sometimes put a whole bunch of them in there, before they realize they need to hit tab to get out of the memo field.

JPG,
I have a CleanMemo.zip file that removes all leading and trailing carriage returns. You can download it from . This is pretty old code (it's from the 2.x days!). It still works, but if I were to write it today, I'd probably do things a little differently.


-BP (Barbara Peisch)
 
Hi Barbara
Thank for your reply.
This my code.


Function TrimMemoEnd
Parameters Pchamp && Memo field
Private Nn,Nb_line
Nb_Line=ALINES(MemoTableau, Pchamp)
M.Ctext=""
For Nn=1 To Nb_Lines
Ctext=Ctext+MemoTableau(Nn)+Iif(Nb_line=Nn,"",chr(13))
Next
Return Ctext
 
JPG,

That's not actually trimming anything from your memo field, you're just adding a CHR(13) to the end of the last line.


-BP (Barbara Peisch)
 
Hi Barbara.

>> That's not actually trimming anything from your memo field, you're just adding a CHR(13) to the end of the last line. <<

Actually, you are mistaken here. ALINES() removes the parse character ( by default it is any combination of chr( 13 ) and chr( 10 ) ) when it shoves the memo into the array.

Actually, the code is adding a carriage return to all the lines except the last one ;-)





Marcia G. Akins
 
Thanks Marcia,
That's true and was exactly what I needed.
JPG
 
OK, but when I copied the code to a PRG and used it to replace a memo field on which I'd stuck a bunch of carriage returns at the end, I still had the carriage returns at the end. That's why I said the code didn't work.


-BP (Barbara Peisch)
 
Hi Barbara.

>> OK, but when I copied the code to a PRG and used it to replace a memo field on which I'd stuck a bunch of carriage returns at the end, I still had the carriage returns at the end. That's why I said the code didn't work. <<

You are absolutely right and I was wrong ;~/ I never even bothered testing the code because it looked right.

The code must be amended as follows to do what it is intended to do:

Code:
lnLines = ALINES( laLines, lcMemo )
lcText = ''
For lnI = lnLines TO 1 STEP -1
  IF EMPTY( laLines[ lnI ] )
    ADEL( laLines, lnI )
    DIMENSION laLines[ ALEN( laLines ) - 1 ]
  ELSE
    EXIT
  ENDIF
NEXT
lnLines = ALEN( laLines )
FOR lnI = 1 TO lnLines
   lcText = lcText + laLines[ lnI ] + IIF( lnI = lnLines, "", chr( 13 ) )
NEXT




Marcia G. Akins
 
Barbara & Marcia
You are definitly right.
I was wrong but the code was OK for me (I just use the Ctext var in a report and I had not any trailing carriage return.

Sorry and thank you for your help.
I'll use YOUR code.
JPG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top