Re: Printing to dot matrix printers
-----------------------------------

The library Example.lsl contains the code needed to print a report
to a dot matrix printer. 

This example assumes that you have a table (however you may have
created it) which contains the data to be printed, and that this
table is unkeyed and unsorted.

The example given prints a financial stock report, and the table
to be printed contains stock records, one per item. The structure of
the table is as follows:

Table 	STOCK.DB

	"ItemCode"     : "A15"
	"Location"     : "A10"
        "BinNumber"    : "A10"
        "QtyOnHand"    : "N"
        "QtyOnOrder"   : "N"
        "AverageCost"  : "$"
	"BrandCode"    : "A10"
	"CategoryCode" : "A10"

Note: The Location and BinNumber are red herrings. The report to
be printed will be grouped by "Category" within "Brand". You could
group it just as easily by "Bin number" within "Location".

Some master tables will also be needed. Let's assume these master
file tables are called "BrandNames.DB", "CategoryNames.DB" and "ItemMaster.DB".
The tables contain, amongst othe information, Brand description,
Category Description and Item Description and have secondary indexes as
follows:

BrandNames.DB has a secondary index ("BrandCode") containing the
field BrandCode, which is unique.

CategoryNames.DB has a compound secondary index ("CategoryIndex")
containing the fields BrandCode and CategoryCode, which is also unique.
Let's also assume that the same categories can apply to different brands.

ItemNames.DB has a secondary index ("ItemCode") containing the field
ItemCode, which is unique.

You can call this method from, for example, a pushbutton on a form as
follows:

var
   libExample    Library
   strPrnPort    String
   strTblName    String
   strRetVal     String
   dtRepDate     Date
endVar

--------------------------------------------------------------------
where strPrnPort is the printer port to which the dot matrix printer
      is attached. This could also be a captured printer port for
      a network printer, eg LPT1, COM2, LPT4 etc.

      strTblName is the name of the table to be printed. In this
      example it's "STOCK.DB".

      strRetVal is a string returned by the method, either "OK"
      (it's worked) or "Cancel" (something went wrong).

      dtRepDate is the report date, to be printed at the top of each page.
---------------------------------------------------------------------

strRetVal = "Cancel"
if libExample.open("Example.LSL") then
   strRetVal = libExample.PrintReport(strTblName, strPrnPort, dtRepDate)
   libExample.close()
endif   
if strRetVal = "Cancel" then
   ------ something went wrong ---------
endif

The library contains a number of global variables (which are used by 
more than one method), each method contains variables only applicable to
the method.

The best place to start working through the code is to look at the
global variables first, then the "PrintReport" method. This method
calls other methods, so work your way through each method as it's
called. I've made comments throughout, but if you have any queries,
feel free to ask pertinent questions in the Paradox newsgroups (where I
lurk a lot <lol>)

Just remember, the basic steps to printing on dot matrix printers
are:

open the textstream      		e.g tsRep.Create(prnPort)

format each line to be printed		e.g strLine = someDataString
						    + space(n)
						    + format("w13, s-, ar", someNumber)
						    + chr(decimal control character)
					etc.

then print the line			e.g. tsRep.WriteLine(strLine)

.
.
.
.

then close the textStream		e.g. tsRep.close()

You can format page headers, group (or band) headers and totals, and
have as many groups (or bands) as you like. You can use printer control
characters to control how your printing looks and make the report as
complex (or as simple) as you wish. All you need are the
basic steps above and your own creativity.

Best of luck

Tom