There are three methods of printing a memo pad. One is to use the MMO'LIN opcode to retrieve one logical print line at a time. The second is retrieve the entire memo into an array in one step using the MMO'OTX opcode, and then print the individual lines of the memo. To use the second method, just set the parameters the same as if you were going to display the memo, except that OPCODE should be set to MMO'OTX, and TEXT should be double mapped as described under MMO'OTX in Calling Parameters section of this document. Then just print the individual lines of the array as you would normally.
The third method is available under A-Shell only, and is described after the more traditional one-line-at-a-time method below.
The first and more traditional method is logically similar to reading a sequential file, one line at a time, and outputting it to a print file as you go. The parameters and procedure for this method are as follows:
opcode should be MMO'LIN
text will receive 1 logical line of memo text.
channel is the memo pad channel number, as in the other memo pad calls.
strow, stcol, endrow and endcol are not used.
link must contain the pointer to the FIRST physical memo record of the memo pad to be fetched. (This is just like in the other memo pad calls.)
pos must be zero for the first call. Normally, it will be zero naturally (unless there was an error on the previous operation, or unless you didn't finish retrieving the previous memo pad.) Note that pos must be mapped as a four byte variable starting at the same memory location as XPOS, which is either a 4 or 6 byte unformatted variable.
The only error condition that you should check for is pos = MMO'LKE (link error) in which case you should either set text = "[LINK ERROR]" and print it or skip printing text. But in either case, you should return to the loop as you would normally and wait for pos to come back as zero (which it will on the next call). This will reset pos properly for the following call.
xpos will be set on return to a value that will enable INMEMO to start from where it left off on the next call. When there is no more text to retrieve in the current memo pad, POS will be set back to zero.
The following section of code shows an example of printing one logical memo pad. It is assumed that LINK points to the start of the memo pad, POS is zero initially (and mapped as in Section 5.0), the memo file channel is 5, and that TEXT is a string. Note that if the memo contains an invisible header, it is returned as the first line, surrounded by chr$(26) characters. Since these don't print very well, we translate them below into brackets; you may choose to just discard them:
PRINT'MEMO'LOOP:
XCALL INMEMO,MMO'LIN,TEXT,CHAN,0,0,0,0,LINK,XPOS
IF POS=MMO'LKE TEXT = "[ILLEGAL LINK]"
IF POS=0 GOTO DONE
PLINE=TEXT ! (PLINE used in PRINT'LINE)
CALL PRINT'LINE ! print 1 line on report
GOTO PRINT'MEMO'LOOP
DONE: ...)
Note that the variable xpos is specified in the XCALL statement, but references are made to pos.
Under A-Shell, you can transfer a logical memo directly to an open print file in one step. The trick is to replace the normal string TEXT parameter with a numeric (B or F) parameter specifying the channel number of a file open for sequential output, as shown below...
OPEN #14, "REPORT.PRT", OUTPUT
<for each record you want to print, CALL PRINT'RECORD...>
PRINT'RECORD:
IF LINCNT > MAXLIN-5 CALL PRINT'HEADER
<print data fields of record on report>
LINK = <link from from data rec>
EXTLIN = MAXLIN-LINCNT ! (max memo lines to output)
EXTMGN = 30 ! (left margin on memo)
PRINT'MEMO:
XCALL INMEMO,MMO'LIN,14,CHAN,0,0,0,0,LINK,XPOS
IF POS=MMO'LKE PRINT #14,"[ILLEGAL LINK]"
IF POS=0 RETURN
! memo too long for page...
CALL PRINT'HEADER
GOTO PRINT'MEMO ! (print rest of memo)