Printing a field

Emma

Member
Hi,

One of the fields in our db is over 300 characters long, and is used to store debug information. The field is viewed in an editor, and has formatting for the positioning. I am assuming these are just blank spaces between words to format it to look as it does. What i need to do is to be able to print this field, as the user sees it in the editor, to their default printer. Does anyone have any ideas as to the best way i can do this?

Kind regards,

Emma.
:blue:
 

Stefan De Leyn

New Member
Hello Emma,
If I understand correctly then the following function should solve your problem. You basically just pass the text on to it and tell it how many characters the seperate pieces of return text can be in length. The function returns the same text to you but split up in pieces, seperated by chr(1) and each piece has the maximum length you have specified.
This then allows you to print the text as you now know that the maximum length of each piece of text will not exceed your page-width.

Hope this solves your problem.

FUNCTION ParseText.
RETURNS CHARACTER
( INPUT charTekst AS CHARACTER,
INPUT intMaxLength AS INTEGER
/* parameter-definitions */ ) :
/*------------------------------------------------------------------------------
Purpose:
Notes:
------------------------------------------------------------------------------*/
DEFINE VARIABLE charTekst2 AS CHARACTER NO-UNDO.

DEFINE VARIABLE intCurrentPos AS INTEGER NO-UNDO.
DEFINE VARIABLE intPrevpos AS INTEGER INIT 1 NO-UNDO.


ASSIGN intMaxLength = intMaxLength - 1
intCurrentPos = intMaxLength
charTekst = REPLACE(charTekst,CHR(10),CHR(1))
charTekst = REPLACE(charTekst,CHR(13),CHR(1)).

DO WHILE intCurrentPos < LENGTH(charTekst) + intMaxlength:
DO WHILE SUBSTRING(charTekst,intCurrentPos,1) <> ' ' AND
SUBSTRING(charTekst,intCurrentPos,1) <> ',' AND
SUBSTRING(charTekst,intCurrentPos,1) <> ';' AND
SUBSTRING(charTekst,intCurrentPos,1) <> ':' AND
SUBSTRING(charTekst,intCurrentPos,1) <> '-' AND
SUBSTRING(charTekst,intCurrentPos,1) <> '.' AND
SUBSTRING(charTekst,intCurrentPos,1) <> '?' AND
SUBSTRING(charTekst,intCurrentPos,1) <> '!' AND
SUBSTRING(charTekst,intCurrentPos,1) <> CHR(10) AND
SUBSTRING(charTekst,intCurrentPos,1) <> CHR(13) AND
intCurrentPos > intPrevPos :

ASSIGN intCurrentPos = intCurrentPos - 1.

END.
IF intCurrentPos = intPrevPos THEN
ASSIGN intCurrentPos = intCurrentPos + intMaxLength.

IF charTekst2 = '' THEN
ASSIGN intCurrentPos = intCurrentPos + 1
charTekst2 = SUBSTRING (charTekst,intPrevPos,intCurrentPos - intPrevPos)
intPrevPos = intCurrentPos
intCurrentPos = intCurrentPos + intMaxLength.
ELSE
ASSIGN intCurrentPos = intCurrentPos + 1
charTekst2 = charTekst2 + chr(1) + SUBSTRING (charTekst,intPrevPos,intCurrentPos - intPrevPos)
intPrevPos = intCurrentPos
intCurrentPos = intCurrentPos + intMaxLength.
END.

RETURN charTekst2. /* Function return value. */

END FUNCTION.
 

laa

Member
I'm a little confused. Why don't you just print it as an editor? Then the data will look just like the editor on the screen.

Anne.
 

laa

Member
The following code is using a variable of course, but it is a simple program that you can run to see what I mean.

DEFINE VARIABLE c AS CHARACTER FORMAT 'x(300)' LABEL "Debug Information".

UPDATE c VIEW-AS EDITOR SIZE 78 BY 4.

OUTPUT TO PRINTER.

DISPLAY c VIEW-AS EDITOR SIZE 78 BY 4.


I hope this helps.

Anne.
 

Stefan De Leyn

New Member
When sending to the standard printer in a windows environment we use the simplest form, namely.

output to printer.

put unformatted 'string'.

output close.

This does not allow this functionallity but is very performant way of printing and that is what our users find more important.
 

Emma

Member
the basic output, put unformatted, does not work correctly. i think that there are char(10) in there to divide each part. what is the simplest way to throw to a new line when there is a char(10) in the field?

Thanks,

Emma
 

Stefan De Leyn

New Member
Put unformatted ignores the chr(10).
One way of throwing to a new line when there is a chr(10) there is to alter the function slightly to replace the chr10) immediately by a chr(1) when encountering it and resetting the counters in the function. Below shows how you can then print the resulting text. In this case we place slightly indented on the page by specifying the "AT 5". "SKIP" then tells Progress to jump to the next line.

ASSIGN charData = DYNAMIC-FUNCTION('ParseText':u,
INPUT charText,
INPUT 65).
REPEAT iCount = 1 TO NUM-ENTRIES(charData,CHR(1)):
PUT UNFORMATTED
ENTRY(iCount, charData, CHR(1)) AT 5
SKIP.
END.
 

Emma

Member
this still doesn't make sense. how does the last lot of code fit in with the previous code for the parsetext function?
 
I suppose a lot of this assumes that the users are viewing the text in an editor with a fixed width text especially if they are expecting text columns to line up.
 

Stefan De Leyn

New Member
Exactly. Above function allows us to print any length of character (what an editor basically is) at any position on a page. This in turn allows us to print the pages with a layout more or less equal to what the user sees on the screen which in turn makes it easier for them to find the information on the printed pages.
 
Top