PRINTER OUTPUT BY BOTH DIRECT MEANS AND USING XCALL
By E. R. (Dick) Metcalfe
The September issue of AMUS Newsletter contained a request from
Stan Kelly-Bootle for some help in making XCALL SPOOL work in
the desired way of operating more than one printer. The
following is one response to that request.
There are set forth two ways to do output to a printer from
inside an AlphaBasic program. The most normally used one is to
build a file, close the file, and then output the file using
the SPOOL subroutine.
Another way, which seems to be faster in operation and which is
especially useful for short outputs or line by line outputs, is
to define the desired terminal or printer as a file. This
"file" is opened, the data printed to the file channel in the
usual manner, and the file channel is closed. Upon closing the
channel, the data are output to the terminal or printer.
Using this latter method, you can even output a log of one set
of printouts on another printer, or you can define another CRT
as "TRM:SOROC2" and have the output appear for monitoring
purposes.
The two methods may be used as follows:
! PRINTER OUTPUT USING "XCALL SPOOL" AND
! ALSO OUTPUTTING DIRECT TO THE PRINTER
! The following is one way to accomplish
! the output to the printer by using
! XCALL SPOOL as the output method,
! especially if you want to first make
! a complete file and then print it
! while you go on to something else
! before printing another
! Be careful about the first line !
! If you fail to give the file an extension
! it will not be printed by the XCALL SPOOL,
! but it will be printed by the direct output
! method. The reason is that the "OPEN"
! command has a default extension of .DAT so
! that a file opened without a specified ex-
! tension will be "FILNAM.DAT". When you
! then ask the XCALL SPOOL for output with
! just the input "filestr", you are asking
! for "FILNAM" and not "FILNAM.DAT".
! Use a routine to check for the presence of
! an extension and add one if needed. Mine
! is at the end, but the gosub is commented out
! so that you may test what I've just said
get'filnam:
input line "Enter file name: ", filestr
if len(filestr) = 0 goto get'filnam
! be sure a file is specified
! gosub extadd
! check for and add extension
open #1, filestr, output
! At this point go off and make the file data
! For this test, use the following
input line "Enter data: ", test'string
! (the next line asks for YOUR printer name)
input line "Enter printer name: ", ptrname
print #1, test'string
print #1, "Output by XCALL SPOOL on file channel #1"
close #1
xcall spool,filestr,ptrname,4+32+128
! Here is another way, especially if you
! want the output to go directly to the
! printer and not to a file.
! It is particularly useful in output of
! data on a line by line basis
! Remember that the AlphaBasic I/O system
! will automatically add a CR and LF to
! the file when it does the INPUT LINE
! so that you will not need to add another
! The first line uses "TRM:DIABLO" as
! the filename for output. Change the map
! statement to suit your printer, or input
! the name as follows:
! The CLOSE #1 will trigger the output
! to the device specified in the defin-
! ition "TRM:DIABLO" (or other printer)
! which in this example is done in the
! "MAP" statement
input "Enter a RETURN to continue with #2: ",x
open #2, ptr, output
! At this point go off and make the file data
! For this test, use the line we input above
? #2, test'string
? #2, "Output by `TRM:DIABLO' on file channel #2"
close #2
goto begin
END
! The following subroutine will check for an
! extension to a filename and add one if needed.
! l is a floating point or binary variable to
! receive the position count, filestr is the
! filename, any desired extension may be added
extadd:
l = instr(1,filestr,".")
if l = 0 filestr = filestr + ".lst"
return
END
Others may know additional and better ways to do the printing
from inside the program, but these are simple and straightforward.