home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource1 / chint / useful20.hnt < prev    next >
Encoding:
Text File  |  1993-10-29  |  2.7 KB  |  51 lines

  1. This hint shows how to modify the standard report skeleton so that it is
  2. easy to get a band to be "repeated".  For example you may wish to print the
  3. same mailing label 3 times.
  4.  
  5.  
  6. The first step is to add a new variable, "repeatcount" and a function to
  7. initialise it.  The "switch (band_no)" cases must be customised for your
  8. particulary application.  Add the following code directly before the
  9. "nextBandRecord" function.
  10.  
  11.  
  12.    int repeatcount[MAX_BANDS+1];                                      /*NEW*/
  13.                                                                       /*NEW*/
  14.    void setRepeatCount(int band_no)                                   /*NEW*/
  15.    {                                                                  /*NEW*/
  16.      switch (band_no) {                                               /*NEW*/
  17.        case 1 : repeatcount[band_no] = 5; break;                      /*NEW*/
  18.      }                                                                /*NEW*/
  19.    }                                                                  /*NEW*/
  20.  
  21. Now we modify the "nextBandRecord" function so it will repeat the appropriate
  22. records.
  23.  
  24.    /* getTheNextKey(indexFilePtr, &recno[theFile], key[theFile], theBand);
  25.       REPLACE THE ABOVE LINE WITH */
  26.       if (repeatcount[theBand] > 1) {                                 /*NEW*/
  27.         repeatcount[theBand]--;                                       /*NEW*/
  28.         recno[theFile] = tempRecordNumber;                            /*NEW*/
  29.         ok = True;                                                    /*NEW*/
  30.       }                                                               /*NEW*/
  31.       else {                                                          /*NEW*/
  32.         getTheNextKey(indexFilePtr, &recno[theFile], key[theFile], theBand);/*NEW*/
  33.         setRepeatCount(theBand);                                      /*NEW*/
  34.       }                                                               /*NEW*/
  35.       if (ok) getarec(theFile);                             /*EXISTING LINE*/
  36.  
  37.  
  38. Finally add another line of code to the end of "establish_link", (this
  39. function comes dierectly after "nextBandRecord()"), just before the
  40. last "}" so that "repeatcount" is initialised.
  41.  
  42.    ...
  43.    *(recordready + theBand) = *(nextrecordready + theBand); /*EXISTING LINE*/
  44.    setRepeatCount(theBand);                                           /*NEW*/
  45.    return;                                                  /*EXISTING LINE*/          /*NEW*/
  46. }                                                           /*EXISTING LINE*/
  47.  
  48.  
  49. Now generate the report using this customized skeleton.  The
  50. "setRepeatCount()" function governs the number of duplicates printed.
  51.