[comp.sys.ibm.pc] How to "print" in dBase

peter@aucs.UUCP (Peter Steele) (04/20/88)

Thanks to all those who replied to my posting concerning the best
way to print in dBase, particularly when preparing custom reports.
It comes down to that if you want to use both ? and @say to output
data in a custom report and suppress output on the screen at the
same time, you have to follow the following outline:

  set console off
  set print on
  set device to print
  --now make your report using ?, ??, and @say's as required,
    as well as any command that uses the "to print" option
    such as report form <whatever> to print
  set device to screen
  set print off
  set console on

It seems to be a rather clumbsy approach but it is how you have
to do it.

I'm including one quite detailed reply that some of you might find
useful. I tried sending info to those who requested it, but is some
cases the mailer kicked it back. So I hope those I couldn't get
via e-mail will see this posting.

--

Peter Steele, Microcomputer Applications Analyst
Acadia University, Wolfville, NS, Canada B0P1X0 (902)542-2201x121
UUCP: {uunet|watmath|utai|garfield}dalcs!aucs!Peter
BITNET: Peter@Acadia  Internet: Peter%Acadia.BITNET@CUNYVM.CUNY.EDU
-------------------------
Reply-To: cline%pnet01@trout.nosc.mil
Message-Id: <8804132036.AA16314@crash.cts.com>
Date: Wed, 13 Apr 88 13:32:23 PDT
From: cline@pnet01.cts.com (Ben Humphreys)
To: aucs!peter
Subject: Re: What is the best way to "print" in dBase?
Status: R

If you wish to print your report to the printer but not to the screen,
issue the following commands:
 
  SET CONSOLE OFF
  SET PRINT ON
  REPORT FORM <form>
  SET PRINT OFF
  SET CONSOLE ON
 
Personally, I have abstained from the SET DEVICE TO CONSOLE/PRINT command.
It is a bit redicilous to issue @ SAY commands and expect them to work with
the printer.  As it is the nature of the printer to advance only forward,
one misplaced @ SAY makes a big mess.
 
While I do not use dBASE any more, I do still use Clipper a lot (a dBASE
compiler).  What I've done to take care of the problems with printing is
this.  I wrote three functions (you'd want to write PROCEDUREs in dBASE).
They are:
 
  FUNCTION PrintStart(output, rep_title)
  FUNCTION PrintLine(line)
  FUNCTION PrintStop(output)
 
PrintStart initializes the page counter and line counter to 1 and 0
respectivly.  It prepars for output using the value of the output variable:
 
  * Constants within the program, C style
  PRINTER = 1
  SCREEN  = 2
  ALTFILE = 3
 
  If output = PRINTER:
    SET CONSOLE OFF
    SET PRINT ON
    STORE .F. TO pause
    STORE .T. TO page_nos
  End
  If output = SCREEN
    SET CONSOLE ON
    SET COLOR TO ...
    STORE .T. TO pause
    STORE .F. TO page_nos
  End
  If output = ALTFILE
    SET CONSOLE OFF
    SET ALTERNATE TO <altfile>
    SET ALTERNATE ON
    STORE .F. TO pause
    STORE .F. TO page_nos
  End
  Print rep_title and other info (time/date/user) in nice format with
    Print()
  Print a line of = characters
 
This being done, all output destined for the report is sent to the Print
function just as it would be sent with ?.  The main difference between
using Print() and ? is you must + all arguements rather than separating
them with a ,.  This also means you must convert all values to strings
before concatinating them with +.
 
When Print() receives a line to print, it takes the following actions:
 
  Prints the line with ?
  Increments the line counter
  If pause = .T. and the line counter is at 23
    Wait
    Restore the line counter back to 0
  End
  If page_nos = .T. and line counter is at 57
    Print 2 blank lines, then a page number
    Eject the printer
    Restore the line counter back to 0
    Increment the page counter
  End
 
When all output is done, a call to PrintStop closes things down:
 
  If pause = .T.
    Wait
  End
  If output = PRINT
    Move to bottom of page
    Print final page number
    Eject the printer
    SET PRINT OFF
    SET CONSOLE ON
  End
  If output = ALTFILE
    SET CONSOLE ON
    SET ALTERNATE OFF
    SET ALTERNATE TO
  Endif
 
The above pseudo-code was not meant in any way to be complete.  It is
rather an outline to the way I wrote my functions.
 
REPORT FORMS, LABELS, ETC
-------------------------
I don't use these commands because of the relative inflexability they pose.
I write all reports manually (this takes longer but overall, the quality is
much better).  With my three print functions,
 
 
Let me know if this has helped.
 

UUCP: {cbosgd, hplabs!hp-sdd, sdcsvax, nosc}!crash!pnet01!cline
ARPA: crash!pnet01!cline@nosc.mil
INET: cline@pnet01.CTS.COM

-- 
Peter Steele, Microcomputer Applications Analyst
Acadia University, Wolfville, NS, Canada B0P1X0 (902)542-2201x121
UUCP: {uunet|watmath|utai|garfield}dalcs!aucs!Peter
BITNET: Peter@Acadia  Internet: Peter%Acadia.BITNET@CUNYVM.CUNY.EDU