Foxpro Printing
Foxpro Printing
Foxpro Printing
http://www.programatica.com/fpage52.html
Page Contents
Other things that they occur when printing
graphically in FPW
Print in character mode in FPW and
Visual FoxPro
GENERIC GENPD
How To Change the Default Source of
Printer Programmatically
Printing Two Reports in One Duplexed
Report
"PDSETUP being
active"
SET PRINTER
FONT command
TO FILE or TO
PRINTER clause
?/?? and @SAY
command
EJECT command
Please note what happens, though, when you execute the following:
02/23/04 11:40
http://www.programatica.com/fpage52.html
*
REPORT FORM {report with no PDSETUP defined} TO PRIN
*
* Since the Report has no PDSETUP defined, issuing t
* above will make FoxPro assume you want no PDSETUP
* printing the report, so it "closes" your LaserJet
* PDSETUP is active during (or after) the report
where {expC1} is the font name, {expN1} is the font size in points (default is 10
points), and {expC2} is the font style (default is standard style). Once you issue
this command, any subsequent printed output to your printer will use that font
definition (unless overridden by a FONT/STYLE clause that some commands
offer. Also note that Reports/Labels with Windows objects will print their objects
as defined in the Report/Label definition and not use the SET PRINTER FONT).
So, for example:
SET PRINTER FONT "Arial",14
LIST STATUS TO PRINTER
2 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
The same happens in FoxPro/DOS. It should be noted, though, that you can get
nice fast character-based output to your printer in FPW by using the command
LIST TO FILE LPT1.
SET PRINTER TO {destination}
LIST TO PRINTER
or
SET PRINTER TO {destination}
SET PRINTER ON
LIST
IF PDSETUP Active
Print to {destination} in character mode using th
ELSE
IF {destination} starts with "PRN" or "LPT"
Ignore the destination and instead print to th
defined for the currently-active Windows Print
with the output being printed in the current S
(In other words, the output is graphically cre
ELSE
Print to {destination} in character mode
ENDIF
ENDIF
Examples:
3 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
If you have no PDSETUP active, then you cant print to a filename that starts
with "PRN" or "LPT". You also cannot print directly to a parallel port. However,
this obstacle can be overcome by using the TO FILE clause instead. FoxPro/DOS
(of course) does not have the same behavior: If you SET PRINTER TO PRN or
LPT1 or LPT2 or LPT3 then output goes to the parallel port no matter what and
destinations that start with "PRN" or "LPT" are considered legitimate filenames
and output goes to a file.
REPORT FORM... LABEL FORM...
The above commands behave exactly like the commands on the previous page
(LIST, DISPLAY, etc). Note that this is only because the Report/Label definition
contains DOS objects only. It should be mentioned once again that if the
Report/Label has no PDSETUP internally defined for it, and one issues the
REPORT/LABEL command with the PDSETUP clause, then Foxpro "turns off"
any PDSETUP that happens to be currently active and then FPW will print the
output using the currently-active Windows Printer Driver.
Well use the REPORT command as an example; the LABEL command behaves
the same way:
REPORT FORM reportdef TO FILE {destination}
FPW prints to the using the currently-active Windows Printer Driver, printing the
report and all its objects as designated in the Report definition (in other words,
graphical output). If the PDSETUP clause is included, it is ignored. If any
PDSETUP is active when the command is issued, it is ignored in favor of the
Windows Printer Driver.
Examples:
4 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
REPORT FORM
Outputs
REPORT FORM
Outputs
Acts the same as the TO FILE example stipulated above except for the fact that
the is ignored completely. FPW assumes that if you want to print TO PRINTER,
then its going to print to the printer that is defined by the currently-active
Windows Printer Driver. It will pay no attention to the you may have defined in
the SET PRINTER TO command.
Examples:
SET PRINTER
REPORT FORM
Ignores
SET PRINTER
SET PDSETUP
REPORT FORM
Ignores
Windows
TO LPT2
windef TO PRINTER
the LPT2 port and prints to the default
TO D:\MYDIR\REPOFILE.TXT
TO "My LaserJet Setup"
windef TO PRINTER
the SET PRINTER TO filename and instead
Printer Driver. The active PDSETUP is i
5 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
It is important to know that you will not see any output until you issue a SET
PRINTER TO command to close the print job.
It should be noted that if a PDSETUP is active, then the @SAY command does
not execute any of the PD functions (which is also true in FoxPro/DOS). The ?/??
command will execute the _PDRIVERs PDOBJECT() function with whatever
STYLE clause you may have stipulated being passed as a parameter to it. The
PDADVPRT() may also be called by a ?/?? command (and ? will cause
PDLINEEND() and PDLINEST() to execute also).
When printing in character mode, there is some strange behavior that goes on
when you mix output using *both* ?/?? and @SAY. It seems that all of the
output from the ?/?? commands get collected into a pool of some sort and the
output from the @SAYs get collected in a separate pool. When you issue the
SET PRINTER TO to close the print job, the pool of ?/?? output gets spit out,
followed by the pool of @SAY output. It seems that an attempt was made to fix
this "pooling" phenomenon in version 2.5a, but it still does not act as it should, as
you will see shortly.
It is interesting to note that even though this behavior is exhibited, the ?/??
6 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
command will still update the values of PROW() and PCOL() correctly. Consider
the following program:
SET PRINTER TO MYFILE.TXT
SET PRINTER ON
SET DEVICE TO PRINTER
?
?? "This is on row "+LTRIM(STR(PROW()))
@ 3,3 say "Row 3 Column 3"
?? " Im on row "+LTRIM(STR(PROW()))
?
?? "Now Im on row "+LTRIM(STR(PROW()))
@ 6,10 say "Row 6 Column 10"
?? " This is on row "+LTRIM(STR(PROW()))
?
?? "Now Im on row "+LTRIM(STR(PROW()))
@ 8,12 say "Row 8 Column 12"
SET DEVICE TO SCREEN
SET PRINTER OFF
SET PRINTER TO
RETURN
+--------------------------------------|
|This is on row 1
|
|
Row 3 Column 3 Im on row 3
|Now Im on row 4
|
|
Row 6 Column 10 This is on ro
|Now Im on row 7
|
Row 8 Column 12
+---------------------------------------
The same program run in FPW 2.5 will output the following garbage:
Actual Row
0
1
2
3
4
5
6
7
8
7 of 27
+--------------------------------------|
|This is on row 1 Im on row 3
|Now Im on row 4 This is on row 6
|Now Im on row 7
|
| Row 3 Column 3
|
|
Row 6 Column 10
|
Row 8 Column 12
+---------------------------------------
02/23/04 11:40
http://www.programatica.com/fpage52.html
+--------------------------------------|
|This is on row 1 Im on row 3
|
| Row 3 Column 3
|Now Im on row 4 This is on row 6
|
|
Row 6 Column 10
|Now Im on row 7
|
Row 8 Column 12
+---------------------------------------
Actually, this can be solved by printing solely using @SAY statements. Just
substitute all instances of "?" with "@ PROW()+1,0 SAY" and all instances of
"??" with "@ PROW(),PCOL() SAY".
Dont mix ?/?? and @SAYs when printing in character mode!!! If you have no
PDSETUP active, then you cant print to a filename that starts with "PRN" or
"LPT" or print directly to a parallel port.
???
The ??? command was introduced into the FoxPro language so that you could
direct output directly to the printer without incrementing PROW() or PCOL(). In
fact, you dont even need SET PRINT to be ON in order for it to work.
Im afraid I still havent figured out all the weird things that this command does.
In general, what it seems to do is (sometimes) close whatever print job may
currently be going on and then starts its own, directing output to the SET
PRINTER TO in character mode. However, if youre printing to a file and if any
@SAY commands had been previously executed before the ???, then the ???
output and all subsequent ?/??/??? output will disappear.
For some examples, consider the following program, called TEST. By the way,
in case youre wondering about why the WAIT WINDOW command is in here,
its to give FPW time to (possibly) start printing the print job that the first ???
command may have closed.
PARAMETERS the_pdsetup,the_dest,atsay_flag
SET PDSETUP TO the_pdsetup
SET PRINTER TO &the_dest
SET PRINTER FONT "Arial",30
SET PRINTER ON
IF atsay_flag
SET DEVICE TO PRINTER
8 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
Press a
Now lets look at some examples using the above program (without
@SAYs):
9 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
+----------------------------------------------|
|Test Line 1Now printing a triple
|Test Line 2Another triple
|Test Line 3
+-----------------------------------------------
10 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
The only scenario in which the ??? command works correctly in concert with
*both* ?/?? and @SAY is when printing to a port (rather than a file) using a
PDSETUP. However, since printing using a PDSETUP is in character mode, the
?/?? and @SAYs do not print correctly in reference to each other (see ?/?? and
@SAY pages in this document). The ??? command *does* work correctly with
the ?/?? command alone in the scenario where you print to a File in ADDITIVE
mode or when you print to a port with a PDSETUP. Bottom line: It looks like
FPW treats the ??? command as a purely DOS feature.
EJECT Command
When _PADVANCE="FORMFEED", the EJECT command essentially just does
a ? CHR(12). Everything works fine with EJECT when running under a
Windows Printer Driver. However, when you have a DOS PDSETUP active and
an EJECT executed just prior to closing your print job, it gets lost. Actually, it
seems to sit around in an internal buffer somewhere and gets output next time
you start a new print job. Consider the following:
_PADVANCE="FORMFEED"
SET PDSETUP TO "Epson-10cpi"
SET PRINTER TO MYFILE1.TXT
EJECT
SET PRINTER TO
PRINTER TO MYFILE2.TXT
PRINTER ON
PRINTER OFF
PRINTER TO
11 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
It seems that sometimes the print job closes too fast for all the linefeeds to get
into the file.
12 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
The decimal portion of the PROW() and PCOL() values are dependent on the
resolution (dots/inch) of your printer. For example, lets look at 10-point
FoxPrint on a 300-dpi Laser Printer. This font has a 12 characters/inch pitch
horizontally, which comes out to 300/12=25 dots/character, so the most
horizontal precision you can achieve in column coordinates is 1/25=0.04. By the
same token, a 10-point character is 10/72 inches tall (1 point=1/72 inch). So
300*10/72=42 dots/character vertically, and vertical precision is 1/42=0.0238. If
we analyzed the same size character on a dot-matrix printer with 144x120
(vertical x horizontal) dots/inch resolution, you could get no more precise than
0.05 units vertically (20 dots) or 0.10 units horizontally (10 dots).
All that this precision stuff above means is that you can only place objects on the
printed page with a limited amount of accuracy, and that depends on your printer.
For example, if I attempt to position the 300-dpi laser print head by issuing the
command @ 12.03,15.03 the print head will *actually* be positioned at the
closest dot coordinate, which is actually 12.0238,15.04. On the 144x120
dot-matrix printer, the actual coordinates would end up being 12.05,15.00. You
can verify this by looking at the values of PROW() and PCOL() when
positioning your output via the @SAY command.
The ? command has an interesting property: It will always move the print head to
the next *integral* printer row. Try the following code:
SET PRINTER ON
SET PRINTER FONT "Arial",10
? "Line 1"
&&Prints in 10-point Arial
? "Line 2"
? "Line 3"
? "Line 4" FONT "Arial",11
? "Line 5" FONT "Arial",11
? "Line 6" FONT "Arial",11
SET PRINTER OFF
SET PRINTER TO
Youll notice that the first 3 lines appear normal, but lines 4 through 6 are spread
apart vertically. This is because FPW is advancing the print head to the next
integral *10-point Arial* row (since that is the active SET PRINTER FONT).
Since 11-point Arial is slightly taller than 10-point Arial, the ? command is
forced to do a line-feed to the next available 10-point row, which ends up being 2
rows below the 11-point line.
13 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
The same thing happens if you mix fonts on the same line. FPW somehow keeps
track of the tallest font and performs a line-feed far enough down for that tallest
font to be visible. Output the following to your printer:
?
??
??
??
?
You will notice that the line of Xs on that second line prints just below the
30-point characters of the first line.
By the way, this "integral row" with the ? command also occurs when outputting
to the screen.
In general, using a PDSETUP will solve the vast majority of your character14 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
GENERIC GENPD
If you dont usually use PDSETUPs, then outlined below is how to create a
whole GENPD application which you can use to force FPW to print
everything in character mode like FP/DOS. Although its essentially useless
(redundant) in FP/DOS, it will work in that environment also.
Step #1: Create a file called GENRICPD.PRG:
*
* GENRICPD.PRG - Generic Printer Driver Setup Prog
*
PARAMETERS calltype,pdname
PRIVATE retval
IF PARAMETERS()=0
&&Called from CONFIG.FP(W)
calltype=0
pdname=""
ENDIF
IF calltype=2
&&Called from FPD Report/Label
RETURN IIF(EMPTY(pdname),"Generic","")
&&Togg
ENDIF
retval=""
IF pdname="?"
&&Called from FPD File/Printer
retval=IIF(EMPTY(_PDSETUP),"Generic","") &&Togg
ELSE
retval="Generic"
ENDIF
_PDRIVER=""
&&Close current Printer Driver
IF NOT EMPTY(retval)
PUBLIC _PDPARMS[3]
_PDPARMS[1]="Generic"
_PDPARMS[2]=.F.
&&PdPageEnd() just executed
_PDPARMS[3]=.F.
&&PdLineEnd() just executed
_PDRIVER="GENRICDV.PRG" &&Open Printer Driver
(calls PDONLOAD if exists)
ENDIF
_PDSETUP="-"+retval
&&The "-" prevents a recurs
RETURN retval
*
* GENRICDV.PRG - Generic Printer Driver Procedures
*
PROCEDURE PdOnUnload
15 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
RELEASE _PDPARMS
RETURN
FUNCTION PdDocSt
PARAMETERS height,width
_PDPARMS[2]=.F.
_PDPARMS[3]=.F.
RETURN ""
FUNCTION PdPageSt
PRIVATE ctlchars
ctlchars=IIF(_PDPARMS[2],CHR(12)+CHR(13),"")
_PDPARMS[2]=.F.
_PDPARMS[3]=.F.
RETURN ctlchars
FUNCTION PdPageEnd
_PDPARMS[2]=.T.
_PDPARMS[3]=.F.
RETURN ""
FUNCTION PdLineSt
PRIVATE ctlchars
ctlchars=IIF(_PDPARMS[3],CHR(13)+CHR(10),"")
_PDPARMS[2]=.F.
_PDPARMS[3]=.F.
RETURN ctlchars
FUNCTION PdLineEnd
_PDPARMS[2]=.F.
_PDPARMS[3]=.T.
RETURN ""
FUNCTION PdAdvPrt
PARAMETERS here,there
_PDPARMS[2]=.F.
_PDPARMS[3]=.F.
RETURN IIF(here>there,CHR(13)+SPACE(there),SPACE(t
FUNCTION PdObject
PARAMETERS theobj,objstyle
_PDPARMS[2]=.F.
_PDPARMS[3]=.F.
RETURN theobj
16 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
You can put this Generic PDSETUP into place by executing the following two
commands:
_GENPD="GENRICPD.APP"
_PDSETUP="Generic"
You may need to fully qualify the GENRICPD.APP in the above _GENPD line
if the APP is in a different directory. You can either execute the above 2
commands from within FPW or put the following 2 lines into your
CONFIG.FPW so that the Generic PDSETUP is in effect every time you start
FPW:
_GENPD="GENRICPD.APP"
PDSETUP="Generic"
_PDSETUP=""
&&Turns the PDSETUP off
_PDSETUP="?"
&&Toggles the PDSETUP on/off
_PDSETUP="-"+{any string} &&Does not actually exe
The reason for the "?" toggle is because of how FoxPro/DOS calls the _GENPD
application from its File Menus Printer Setup Option. And, as outlined in the
FoxPro Printer Driver documentation, setting _PDSETUP to any string that starts
with a dash ("-") will set the _PDSETUP system variable to the portion of the
string after the dash, but will not actually execute the _GENPD application.
Once you have the Generic PDSETUP active, then all printer output in FPW will
be just like printing without a PDSETUP in FoxPro/DOS, as long as you follow
the rules I stipulated in the "Print in character mode" section of this document.
17 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
dwCommand)
Obtain the hPrinter parameter from OpenPrinter() as a handle that identifies the
desired printer. Set the dwLevel parameter to 2, and point lpbPrinter to the
PRINTER_INFO_2 structure. Set the dwCommand parameter to 0. Fill out the
PRINTER_INFO_2 structure appropriately.
There are few ways of changing the (upper/lower) printer tray dynamically. The
most common is to use PCL printer commands. To do this, insert the escape
sequence in the file, along with the content you are trying to print. Unfortunately,
this method makes it difficult to work with Visual FoxPro since you are limited
by the printers settings (you need to know the designated printer beforehand),
and the reports in Visual FoxPro use the printer driver internally once the
printing job is established.
The following sample program illustrates the contents of the .dll file written in
Microsoft Visual C++ 4.0. It shows a way to retrieve a handle identifying the
specified printer or print server.
NOTE: This sample program illustrates many Microsoft Visual C++ commands.
The use of these commands is beyond the scope of Microsoft FoxPro Product
Support. Users with substantial experience using API routines should be able to
write the following sample .dll file. For this sample to work, you need a .def file
to export the chgbin function.
Sample Program (DLL to Change the Default Source of Printer)
#include "stdio.h"
#include <windows.h>
02/23/04 11:40
http://www.programatica.com/fpage52.html
return 1;
UNREFERENCED_PARAMETER(hInst);
UNREFERENCED_PARAMETER(ul_reason_being_called);
UNREFERENCED_PARAMETER(lpReserved);
}
#define ErrReturn
if (GetLastError()) {ClosePrinter(hPrinter);
}
#define UPPER_BIN 1
#define LOWER_BIN 2
int APIENTRY chgbin(char *ptrname, int flg)
{
HANDLE
DWORD
DWORD
LPTSTR
short
hPrinter = NULL;
cbBuf;
pcbNeeded = 0;
pPrintername;
nSource;
pPrintername = ptrname;
PRINTER_DEFAULTS pd;
ZeroMemory(&pd, sizeof(pd));
pd.DesiredAccess = PRINTER_ALL_ACCESS;
int result1 = OpenPrinter(pPrintername,&hPrinter, &pd);
ErrReturn;
int result = GetPrinter(hPrinter, 2, NULL, 0, &pcbNeeded);
DWORD Error = GetLastError( );
if( Error == ERROR_INSUFFICIENT_BUFFER )
{
BOOL bRet = FALSE;
HANDLE hMem = NULL;
LPPRINTER_INFO_2 pPrinter;
19 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
>pDevMode,pPrinter->pDevMode,
DM_IN_BUFFER|DM_OUT_BUFFER);
SetPrinter(hPrinter,2,(unsigned char *)pPrinter,0);
MyFreeMem(pPrinter);
ClosePrinter(hPrinter);
}
}
Error = GetLastError( );
return 0;
}
typedef struct _tagDevCaps {
TCHAR
pPrinterName[80];
TCHAR
pPort[80];
WORD wCurCap;
WORD
wCurPlatForm;
HINSTANCE hDriver;
//only used if on Win32s;
DWORD (CALLBACK* pfnDevCaps) (
LPTSTR
pDevice,
// address of device-name string
LPTSTR
pPort, // address of port-name string
UINT
fwCapability, // device capability to query
LPTSTR
pOutput,
// address of the output
LPDEVMODE pDevMode
// address of structure with device data
);
} DEVCAPS;
LPVOID MyAllocMem(DWORD cb) {
}
20 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
#define MAX_AMOUNT
#define MAX_BINS
16
256
dwBufSize = 0;
bResult = 1;
*pawBinList;
if (MyDevCaps.pfnDevCaps)
{
// get number of bins
dwBufSize = MyDevCaps.pfnDevCaps ((LPTSTR )MyDevCaps.pPrinterNam
)MyDevCaps.pPort, (WORD)DC_BINS,
(LPTSTR )pawBinList, (LPDEVMODE)NULL);
// display bin info
// protects from bad drivers
if ((dwBufSize > 0) && (dwBufSize < MAX_AMOUNT))
{
for (int i=0; i< (int)dwBufSize;i++)
{
if (pawBinList[i] < MAX_AMOUNT)
{
if (pawBinList[i] < MAX_BINS)
{
if (flg == UPPER_BIN && pawBinList[i] == UPPER_BIN)
return (pawBinList[i]);
else if (flg == LOWER_BIN && pawBinList[i] == LOWER_BIN)
21 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
return (pawBinList[i]);
}
}
}
}
// clean up
MyFreeMem(pawBinList);
return (-1);
}
return (-1);
}
In the FoxPro Application
DECLARE integer chgbin IN c:\bin.DLL STRING, INTEGER
** 1 = Upper
2 = Lower
retval = chgbin("HP LaserJet 4Si MX",2)
USE CUSTOMER
LIST TO PRINT
02/23/04 11:40
http://www.programatica.com/fpage52.html
02/23/04 11:40
http://www.programatica.com/fpage52.html
the default directory. Please take note of the names of the files so as not to
overwrite any files you may already have (since SAFETY is turned OFF). These
temporary files are not deleted, but could be with only a few additional lines of
code.
**=========================================**
** Begin program
**
**=========================================**
******* Environment Settings
** Printer Settings... this allows the user to
** choose which printer settings will be used in
** creating the file. But remember, the file
** will still be sent to the port indicated in
** the COPY FILE command at the end of the program.
SET PRINTER TO GETPRINTER()
** Safety should be off in case we have
** already run this procedure before
tmpsafe = SET("SAFETY")
SET SAFETY OFF
******* End environment settings
******* Create template file
** Create blank report
IF FILE("blank.frx")
DELETE FILE blank.frx
ENDIF
DEFINE WINDOW test FROM 0,0 TO 10,10
KEYBOARD "{CTRL+W}"
CREATE REPORT blank
RELEASE WINDOW blank
RELEASE WINDOW test
** Change the printer settings to ensure duplex printing is
** turned on and use selected settings. Please note that
** duplex printing will work only on printers that support it.
USE blank.frx
REPLACE expr WITH "DUPLEX=2" && turn duplex on
USE
** Create blank table to cover two pages
SELECT 0
IF USED("blank")
USE IN blank
ENDIF
IF FILE("blank.dbf")
DELETE FILE blank.dbf
ENDIF
CREATE TABLE BLANK (test C)
FOR nCnt = 1 TO 25
APPEND BLANK
24 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
ENDFOR
** Create template print file from blank report
REPORT FORM blank TO template.prn
USE IN blank
** Create variables for each line of the template file
htemplate = FOPEN("template.prn")
linecnt = 0
DO WHILE !FEOF(htemplate)
linecnt = linecnt + 1
lnvar = "line" + ALLTRIM(STR(linecnt))
STORE FGETS(htemplate) TO &lnvar
ENDDO
=FCLOSE(htemplate)
******* End create
25 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
SELECT one
REPLACE expr WITH rtmp
USE IN one
&& Second report
USE (report2) IN 0 ALIAS two
SELECT two
REPLACE expr WITH rtmp
USE IN two
** Determine the size of the input files
tmpdb4 = SET("COMPATIBLE")
SET COMPATIBLE ON
onesz = FSIZE("one.txt")
twosz = FSIZE("two.txt")
SET COMPATIBLE &tmpdb4
******* End process
******* Create final print file
** Delete the file, if it exists, and create
** a new file to contain the reports
IF FILE("final.prn")
DELETE FILE final.prn
ENDIF
hFinal = FCREATE("final.prn")
** Write header codes
totchar = 0 && this will contain the length of the header
FOR nCnt = 1 TO linecnt-2
lnvar = "line" + ALLTRIM(STR(nCnt))
totchar = totchar + FPUTS(hFinal,EVAL(lnvar))
ENDFOR
pgvar = "line" + ALLTRIM(STR(linecnt-1)) && page break line
ejvar = "line" + ALLTRIM(STR(linecnt)) && end of job line
** Write body of first report file
hOne = FOPEN("one.txt")
=FSEEK(hOne,totchar-(linecnt-2))
=FWRITE(hFinal,FREAD(hOne,onesz-totchar-LEN(EVAL(ejvar))))
** Write pagebreak codes
=FPUTS(hFinal,EVAL(pgvar))
** Write body of second report file
hTwo = FOPEN("two.txt")
=FSEEK(hTwo,totchar-(linecnt-2))
=FWRITE(hFinal,FREAD(hTwo,twosz-totchar-LEN(EVAL(ejvar))))
** Write end-of-job codes
=FPUTS(hFinal,EVAL(ejvar))
** Close all files
=FCLOSE(hFinal)
26 of 27
02/23/04 11:40
http://www.programatica.com/fpage52.html
=FCLOSE(hOne)
=FCLOSE(hTwo)
******* End create
******* Send the final file to the printer
** This line copies the file to the printer
** connected to LPT1: in Windows. You may also
** specify LPT1 or LPT2 instead of PRN.
COPY FILE final.prn TO PRN
******* End send
******* Restore Environment Settings
SET SAFETY &tmpsafe
******* End restore
**=========================================**
** End program
**
**=========================================**
Hosted By
Programatica WEBDesign
27 of 27
02/23/04 11:40