home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Interactive Guide
/
c-cplusplus-interactive-guide.iso
/
c_ref
/
csource1
/
chint
/
useful26.hnt
< prev
next >
Wrap
Text File
|
1993-10-29
|
8KB
|
262 lines
This useful hint shows how to modify the standard report skeleton to enable it
to print multiple copies of a report.
2
1) The first step is to copy the standard report skeleton to a new file so
that the original remains intact :--
COPY DBCREP.SKL NCOPIES.SKL
Now we will make the modifications to this skeleton. When you want a
report to have acces to this functionallity just change the skeleton
name on hte report GENERATE screen from DBCREP.SKL to NCOPIES.SKL.
2) Add a new global variable :--
int numberofcopies;
3) We need to break the "initialize()" function into two parts, and also
prototype the new function "sub_initialize". Then inside the
"InitializeReport" function we will introduce a new local loop variable,
then run a "for" loop to repeat the printing of the report :--
/*
****************************************************************************
** Function : subinitialize
**
** Arguments : None
** Returns : None
**
** This function resets global variable. It can be called each time around
** a loop the repeatedly prints the report, ("numberofcopies" times).
**
****************************************************************************
*/
void subinitialize(void) /*MOD MC*/
{
int counter;
skip = True;
textadded = True;
filtererror = False;
mainprted = False;
pagetoprint = False;
supresspage = False;
scrn_active = True;
terminate = False;
splitmemobegun = False;
blanks = 0;
gxpos = 0;
pageno = 1;
lineno = 1;
*errorMessage = '\0';
/* initialise the memos, totals and records counters */
for (counter = 0; counter <= MAX_MEMOS; counter++) (memostatus + counter)->memoref = *(extralines + counter) = 0;
for (counter = 1; counter <= MAX_TOTALS; counter++) clearTotals(counter);
for (counter = 1; counter <= MAX_BANDS; counter++) {
*(break_ + counter) = None;
*(recordsread + counter) = *(recordsprinted + counter) = *(bandstartlno + counter) = 0;
}
totalrecordsread = 0;
totalrecordsprinted = 0;
}
/*
****************************************************************************
** Function : initialize
**
** Arguments : None
** Returns : (int) - status (0-Unsuccesful, 1-Successful)
**
** This function attempts initialise the included functions and variables,
** as well as any runtime variables, followed by opening all the input
** files.
**
****************************************************************************
*/
int initialize(void)
{
int counter, okStatus, stringLength;
/* initialise the DataBoss header routines and variables */
extfhc_init();
db_curs_init();
db_date_init();
db_funcs_init();
db_heap_init();
db_gvar_init();
db_key_init();
db_win_init();
db_util_init();
db_tree_init();
db_list_init();
db_uwin_init();
ⁿIFDEF MEMOSⁿ
db_memo_init();
ⁿENDDEFⁿ
ⁿIFDEF MUSERⁿ
multiuser = True;
ⁿELSEDEFⁿ
multiuser = False;
ⁿENDDEFⁿ
#ifdef F_USED
_keyexpr = keyExpression;
_getarec = getarec;
_horizrec = horizrec;
#endif
/* reserve an output device handle early */
outputFileHandle = open("CON", O_CREAT | O_BINARY | O_WRONLY, S_IREAD | S_IWRITE);
/* initialise runtime variables */
numberofcopies = 1; /*MOD MC*/
strcpy(iodev, ⁿIODEVⁿ);
strcpy(dsk_file, ⁿDISKFILEⁿ);
strconcat(dbname,datapath,"\\",dbnames[bandlink[1].thisfile][0],NULL);
strcpy(progname,thisprog.fpath);
fok = True;
deltas = 0; /* Turn Screen Save Off */
okStatus = True;
pabort = False;
pmode = IBMGraphics;
subinitialize(); /*MOD MC*/
tmpbuf = (BYTE *)db_malloc(4097 * sizeof(BYTE));
mbuf = (char *)db_malloc((MEMBUFSIZ + 1) * sizeof(char));
/* clear the screen and initialise the edit fields, indexes and storage space */
clrscr();
initedit();
initindex();
/* check to see if the program is allowed to run from DOS */
if (menudriven && (!dbcaller)) {
strcpy(errorMessage, LSC_MenuDriven);
goto initializeError;
}
/* check to see if the directory path passed for the datafiles is valid */
if (!validpath()) {
strcpy(errorMessage, LSC_AbortBadPath);
goto initializeError;
}
/* display the opening "Initialising" window and if successful open all the files */
if (displayWindowMessage(LSC_Initializing)) {
openFiles();
closewin(&twinp);
if (!fok) {
strcpy(errorMessage, LSC_ErrNeededFiles);
goto initializeError;
}
}
else {
strconcat(errorMessage, LSC_Window, " : ", DOSErr8, NULL);
goto initializeError;
}
/* get the values for the report Range */
ⁿGETRANGEⁿ
/* check to see if an error occurred during entering of filter data */
if (filtererror) {
strconcat(errorMessage, LSC_BadOpenFilter, " : ", rw.wfnam,NULL);
goto initializeError;
}
/* check for output to screen, if so set the relevant controls */
if (strstr(iodev, "CON")) {
pagelength = 24;
pause = True;
clrscreen = True;
}
/* allocate heap memory for report storage */
if (!allocateReportData()) {
strcpy(errorMessage, DBTErr203);
goto initializeError;
}
goto initializeExit;
initializeError:
okStatus = False;
displayError(errorMessage);
initializeExit:
errorScreenInitialize();
return(okStatus);
}
/*
****************************************************************************
** Function : processReport
**
** Arguments : None
** Returns : None
**
** This function performs the actual processing of the report.
**
****************************************************************************
*/
void processReport(void)
{
int loops; /*MOD MC*/
for (loops = 1; loops <= numberofcopies; loops++) if (!terminate) { /*MOD MC*/
subinitialize(); /*MOD MC*/
establish_link(1);
printReportHeaderOrFooter(RPHDR);
printPageHeader();
ⁿPRINTⁿ
if (pagetoprint) {
printPageFooter();
outputPage();
}
printReportHeaderOrFooter(RPFTR);
} /*MOD MC*/
return;
}
This completes the work necessary to get the report to print multiple copies.
what you will now need is a way to set the number of copies. This could be
achieved simplisically by changing the the value to which "numberofcopies" is
initialized in the "Initialize" procedure.
A better idea is to give the user the option of to specify the number of
copie at run time. To do this you would design a filter screen with a prompt
like :--
How many copies :
Now add the folowing filter fields :--
Field Name Seq Typ Mode Pic Validation
---------- --- --- ---- --- ----------
GET_COPIES 1 N E 2# !{} > 0
Field Name Seq Typ Mode Pic Compute Expression
---------- --- --- ---- --- ----------------------------------
SET_COPIES 2 C C X numberofcopies = ival(GET_COPIES)
You can attach this filter to any report that is generated using the
NCOPIES.SKL skeleton file.