home *** CD-ROM | disk | FTP | other *** search
/ Share Gallery 1 / share_gal_1.zip / share_gal_1 / DB / DB012B.ZIP / VPI1MANL.ZIP / CHARITY.ZIP / CHARITY.DOC next >
Text File  |  1991-12-29  |  19KB  |  442 lines

  1. ***************************************************************************
  2. **  CHARITY.ZIP
  3. **  (C) Copyright 1990, Sub Rosa Publishing Inc.
  4. **  A demonstration application provided to VP-Info users.
  5. **  This program may be copied freely. If it is used in commercial code,
  6. **  please credit the source, Sub Rosa Publishing Inc.
  7. **
  8. **  This suite of programs provides an actual example of a complete
  9. **  application, written in VP-Info, the data base language published
  10. **  by Sub Rosa Pulishing Inc.
  11. **
  12. **  This is a demonstration application. Some techniques are
  13. **  used primarily to enrich the variety of examples used, even if they
  14. **  would usually not all be used in a single application.
  15. **
  16. **  The entire application is compatible with all Sub Rosa Publishing
  17. **  editions of VP-Info.
  18. **
  19. **  Sid Bursten and Bernie Melman
  20. **  June, 1990
  21. ***************************************************************************
  22.  
  23.  
  24.  
  25.           Programmers may find it helpful to study an actual application,
  26.      complete with most of the features available to Info users.
  27.  
  28.           Although many additional features could easily be added, this
  29.      example is designed to showcase techniques as simply as possible while
  30.      providing a useful skeleton for real organizations to use.
  31.  
  32.      CHARITY.ZIP should be un-zipped in a hard-disk directory of its own.
  33.  
  34.           It assumes that a charitable organization has a cadre of
  35.      solicitors who canvass the public for pledges of support for the
  36.      cause.  Once pledges are received, the charity has to log funds as
  37.      they are received from the donors, keeping information on how many
  38.      dollars are collected on pledges in both the donor and solicitor data
  39.      files.
  40.  
  41.           The application has three data files with the following
  42.      structures:
  43.  
  44.                Data file:         DONATE.DBF
  45.                Field   Name       Type   Width  Dec
  46.                  1     DONOR        C        6
  47.                  2     SOLICITOR    C        6
  48.                  3     DATE         C        6
  49.                  4     AMOUNT       N        8    2
  50.                  5     HOWPAID      C        1
  51.                ** Record Length **          28
  52.  
  53.  
  54.                        CHARITY.DOC                                  Page 2
  55.               Data file:         DONOR.DBF
  56.                Field   Name       Type   Width  Dec
  57.                  1     DONOR        C        6
  58.                  2     FNAME        C       15
  59.                  3     NAME         C       15
  60.                  4     ADDRESS      C       30
  61.                  5     CITY         C       18
  62.                  6     STATE        C        2
  63.                  7     ZIP          C        9
  64.                  8     PLEDGE       N        8    2
  65.                  9     PAID         N        8    2
  66.                 10     SOLICITOR    C        6
  67.                ** Record Length **         118
  68.  
  69.                Data file:         SOLICIT.DBF
  70.                Field   Name       Type   Width  Dec
  71.                  1     SOLICITOR    C        6
  72.                  2     FNAME        C       15
  73.                  3     NAME         C       15
  74.                  4     ADDRESS      C       30
  75.                  5     CITY         C       18
  76.                  6     STATE        C        2
  77.                  7     ZIP          C        9
  78.                  8     PLEDGE       N        8    2
  79.                  9     PAID         N        8    2
  80.                ** Record Length **         112
  81.  
  82.           Execution begins with DONMENU, which is built around the MENU(
  83.      function.  By selection an option numbered 0 through 9, the user
  84.      selects a free-standing program, a subroutine, a procedure, a report
  85.      form or exit from the program or from Info altogether.
  86.  
  87.           The menu screen and selection is set up with the following
  88.      commands:
  89.  
  90.      WINDOW 1,2,23,77 double    ;draw border and force all display inside
  91.      SET date to 'yymmdd'       ;default to years first; allows date sort
  92.      SET talk off               ;suppress messages like NO FIND
  93.      SET text on                ;include display fields in GET TABLE for
  94.      READ
  95.      SET trim off               ;do not trim & macros in TEXT display
  96.      SET execution off          ;don't re-execute ON FIELD on exit
  97.      SELECT 1
  98.      ERASE
  99.      @ 1,3 SAY date(full)
  100.      @ 3,3 SAY cen(:company,74) ;display company name on menu
  101.      @ 5,3 say cen('Main Menu',74)
  102.      WINDOW 8,25,22,77 blank    ;create invisible window to position text
  103.  
  104.  
  105.                        CHARITY.DOC                                  Page 3
  106.      TEXT
  107.       0. Enter Conversational Mode
  108.  
  109.       1. Enter/Edit Donations
  110.       2. Enter/Edit Donors
  111.       3. Enter/Edit Solicitors
  112.       4. Post Donations
  113.       5. Report Donations
  114.       6. Report Solicitors
  115.       7. Print Labels
  116.       8. Reindex All Files
  117.       9. Exit to the Operating System
  118.      ENDTEXT
  119.      WINDOW                     ;window no longer needed
  120.      SET width to 80            ;restore line width for later text displays
  121.      CURSOR 10,23               ;position cursor for MENU( function
  122.      CLEAR keyboard             ;empty type-ahead buffer
  123.      ANS=menu(9,38)             ;9 options, with bar 38 characters wide
  124.  
  125.           Note that a bordered window is created to display the menu, along
  126.      with the current date, the company or organization name and the menu
  127.      title.  Then an invisible window is created into which the TEXT block
  128.      is positioned.  Using WINDOW with the BLANK option is much easier than
  129.      attempting to center text in the program itself.
  130.  
  131.           Once the window is no longer needed, it is canceled, the cursor
  132.      is correctly placed and the keyboard buffer is emptied to eliminate
  133.      characters that may have been inadvertently left over from an earlier
  134.      program.  Finally, the user enters his choice from the options given.
  135.  
  136.           Choice zero cancels execution and puts the user into
  137.      Conversational Info, while option 9 exits Info and returns to DOS.
  138.  
  139.  
  140.      Data Entry with TEXT
  141.  
  142.           Option 1 chains to the program ENTRY, which in turn chains back
  143.      to DONMENU when complete.  ENTRY edits and adds records in the DONATE
  144.      data file, which contains one record for each payment made.  The user
  145.      enters the code number of the donor, which the program uses to
  146.      retrieve the donor's name and address, and the code number of the
  147.      solicitor; the name of the solicitor is then retrieved from the
  148.      SOLICIT data file.
  149.  
  150.           Both donors and solicitors are assigned unique code numbers by
  151.      the computer in options 2 and 3, which enters and edits records of
  152.      these individuals.  The code number consists of the first three
  153.      characters of the last name, the first initial, and a two-digit serial
  154.      number that starts at 01 and goes up to 99 as people are added with
  155.      similar names.  This method makes it easy to find code numbers, yet
  156.      assures a large number of unique code numbers.
  157.  
  158.  
  159.  
  160.                        CHARITY.DOC                                  Page 3
  161.  
  162.           The subroutine DONEDIT is used to add donor records to DONOR.DBF.
  163.      An input screen is retrieved from a library (DONATE.LIB) and is
  164.      activated with READ.  All of the functions normally available in EDIT
  165.      are obtained by checking the value of KEY, a system variable
  166.      containing the number of the key used to exit READ.
  167.  
  168.           The TEXT stored as library volume .1:
  169.  
  170.           The prompt box at the top is similar to that provided by EDIT
  171.      with SET MENU ON.  Note that double carats (^^) are needed to print a
  172.      single carat on the screen, since carat has a special meaning to TEXT.
  173.  
  174. .. donor,!!!-!-99
  175. .. solicitor,!!!-!-99
  176. .. state,!!
  177. .. zip,!!!!!!!!!
  178. ┌─────────────────────────────────────────────────────────────────────────────┐
  179. │REC:  prev <PgUp>  next   <PgDn>                    Delete current record ^^U │
  180. │FILE: top  ^^<Home> bottom ^^<End>       DELETE: char <Del> to end of field ^^Y │
  181. │APPEND MODE: begin ^^<PgDn> exit <PgUp>     EXIT: with save <End>  no save ^^Q │
  182. └─────────────────────────────────────────────────────────────────────────────┘
  183.  
  184.                    Enter or edit donors and pledges
  185.  
  186.  
  187.      Name (first/last)... %fname %name
  188.      Code Number......... #donor
  189.  
  190.      Address............. @address
  191.      City and State...... %city %state
  192.      Zip Code............ @zip
  193.  
  194.      Pledge Amount....... @pledge           Paid to date....... #paid
  195.      Solicited by........ @solicitor
  196.                           &fname#2 &name#2
  197.  
  198.           This sample uses all four macro symbols.  Inputs are indicated by
  199.      @ and %, while display-only fields are indicated by # and &.  The @
  200.      and # symbols are used for fixed-position fields, while % and & are
  201.      used for floating-position fields.  This TEXT requires SET TEXT ON and
  202.      SET TRIM OFF, both of which are in DONMENU.
  203.  
  204.           FNAME and NAME, and CITY and STATE, use the floating symbols
  205.      since we only want to ensure the fields have a space between them no
  206.      matter how long they are.
  207.  
  208.           Four of the fields require specific format pictures, which are
  209.      given at the top on lines starting with two periods.
  210.  
  211.           Here are the commands that create the code number inside the DO
  212.      WHILE structure whenever a new record is created:
  213.  
  214.  
  215.                        CHARITY.DOC                                  Page 4
  216.  
  217.      recnum=#                         ;store current record number
  218.      finder=!(left(mname,3)+left(mfname,1))  ;build alpha part of code
  219.      finder=replace(finder,' ','*')   ;fill in blanks in code with asterisks
  220.  
  221.      FIND &finder   ;these 6 lines are equivalent to the LAST command,
  222.      IF #>0         ;  although LAST is substantially faster. Essentially,
  223.         LIMIT 4     ;  all we have to do is find if a record exists with
  224.         GOTO bottom ;  the same 1st 4 letters of the code, and find out
  225.      LIMIT          ;  what the last serial number is so we can increment
  226.      ENDIF          ;  it.
  227.  
  228.      The previous 6 lines in Level 1 code can be replaced by the single line
  229.      LAST &finder                     ;find last matching code in file
  230.      in VP-Info versions which support the LAST command.
  231.  
  232.      IF #=0
  233.         finder=finder+'01'
  234.      ELSE
  235.         num=val(right(donor,2))  ;get number of last matching record
  236.         IF num<99                ;only allow numbers up to 99
  237.            finder=finder+right(str(101+num,3),2) ;increment with leading zero
  238.         ELSE
  239.            finder='******'  ;overflow if already 99 records with same letters
  240.         ENDIF
  241.      ENDIF
  242.      GOTO recnum      ;go back to original record and fill in name and code
  243.      REPLACE fname with mfname,name with mname,donor with finder
  244.  
  245.           This TEXT has an associated ON FIELD structure, which among other
  246.      things does lookups into the DONOR and SOLICIT data files.  Here's the
  247.      section that does it:
  248.  
  249.      IF solicitor<>solicitor#2
  250.         FIND#2 &solicitor#1  ;align file when solicitor code filled in
  251.         IF recno(2)=0
  252.            :field=field(solicitor)
  253.            @ 23,0 say cen('No solicitor found with this code number.',80)
  254.         ELSE
  255.            :field=field(fname)
  256.            @ 23,0
  257.         ENDIF
  258.      ENDIF
  259.  
  260.           The reason the FIND is inside an IF is that it would waste time
  261.      and effort to align the files when they are already aligned.
  262.  
  263.  
  264.  
  265.                        CHARITY.DOC                                  Page 5
  266.  
  267.      Posting Totals to a Data File
  268.  
  269.           One of the most useful functions of a relational database system
  270.      is the ability to accumulate totals from fields in one data file into
  271.      another data file.
  272.  
  273.           In this application we want to add up all the pledges and
  274.      receipts for each donor and each solicitor.
  275.  
  276.           The first step is to zero out the totalling fields in the
  277.      respective files.  Then an index is set to establish the relation and
  278.      the POST command invoked.
  279.  
  280.           In this application, we've added a complication: limiting the
  281.      records to be posted to donations made within a specified period.
  282.  
  283.           The following commands do the posting, depending on whether
  284.      beginning and/or ending dates are specified:
  285.  
  286.      DO CASE
  287.      CASE finish<'999999' .and. start>' '
  288.         POST on solicitor from donate fields paid with amount for
  289.                                    date>=start .and. date<=finish
  290.         POST#2 on donor from donate fields paid with amount for date>=start
  291.                                    .and. date<=finish
  292.      CASE finish<'999999'
  293.         POST on solicitor from donate fields paid with amount for
  294.                                    date<=finish
  295.         POST#2 on donor from donate fields paid with amount for
  296.                                    date<=finish
  297.      CASE start>' '
  298.         POST on solicitor from donate fields paid with amount for
  299.                                    date>=start
  300.         POST#2 on donor from donate fields paid with amount for date>=start
  301.      OTHERWISE
  302.         POST on solicitor from donate fields paid with amount
  303.         POST#2 on donor from donate fields paid with amount
  304.      ENDCASE
  305.  
  306.           An unusual feature of the POST command is the ability (with SET
  307.      ADD ON) to add records to the target data file automatically if no
  308.      record is found to accumulate totals to for unknown or incorrect
  309.      records in the source file.  This assures complete posting, since no
  310.      amounts are "lost."
  311.  
  312.  
  313.                        CHARITY.DOC                                  Page 6
  314.  
  315.      Reporting
  316.  
  317.           The menu offers two report options.  The simpler one merely lists
  318.      all the solicitors in code-number order, with the amounts posted from
  319.      the DONOR and DONATE data files.
  320.  
  321.           The list of donations, however, has two additional features:
  322.  
  323.           A.   The report uses two additional related files, so the names
  324.                of both the donor and solicitor can be shown
  325.  
  326.           B.   The same date feature mentioned for posting is used, again
  327.                in an ON CASE structure, to optimize the report depending on
  328.                whether beginning and/or ending dates are specified
  329.  
  330.      Printing Labels
  331.  
  332.           There are a number of complexities to printing labels,
  333.      particularly 2 or more across.
  334.  
  335.           Among these is how to handle records with one or more missing
  336.      pieces of data.  For example, many small-town residents have only the
  337.      town name as an address; merely printing name, address and city on
  338.      three separate lines would leave a blank line in this case.
  339.  
  340.           The subroutine DONLABEL uses a 3x3 matrix to organize the data
  341.      for up to three labels at once, and a second 3x3 matrix is used to
  342.      print the labels.
  343.  
  344.           The matrixes are created in DONMENU as follows:
  345.  
  346.      DIM char 32 label[3,3]     ;matrix for 3-across labels
  347.      DIM char 34 labelout[3,3]  ;actual output matrix for 3-across labels
  348.  
  349.           Since Info adds one space between horizontal elements of a
  350.      matrix, LABELOUT has 35 characters between the start of one label and
  351.      the start of the next . . . 3.5 inches as normal printer pitch.
  352.  
  353.           LABEL is about a quarter of an inch narrower; this increases the
  354.      margin between labels to about a third of an inch without changing the
  355.      position of the labels themselves.
  356.  
  357.           DONLABEL is fully commented, and is used to print labels for both
  358.      SOLICIT and DONOR data files.
  359.  
  360.  
  361.  
  362.                        CHARITY.DOC                                  Page 7
  363.      Maintaining Indexes
  364.  
  365.           Every application requires not only a set of index files, but an
  366.      easy way of creating and correcting those index files.  The indexes
  367.      used in this application are maintained with the following module:
  368.  
  369.      SET talk on   ;show progress of indexing...? lines show steps to do
  370.      ? "USE donate"
  371.      USE donate
  372.      ? "INDEX on donor+date to donatdon"
  373.      INDEX on donor+date to donatdon
  374.      ? "INDEX on solicitor+date to donatsol"
  375.      INDEX on solicitor+date to donatsol
  376.      ? "INDEX on date+donor to donatdat"
  377.      INDEX on date+donor to donatdat
  378.      ? "USE donor"
  379.      USE donor
  380.      ? "INDEX on !(name)+left(fname,1) to don_name"
  381.      INDEX on !(name)+left(fname,1) to don_name
  382.      ? "INDEX on donor to don_code"
  383.      INDEX on donor to don_code
  384.      ? "USE solicit"
  385.      USE solicit
  386.      ? "INDEX on !(name)+left(fname,1) to sol_name"
  387.      INDEX on !(name)+left(fname,1) to sol_name
  388.      ? "INDEX on solicitor to sol_code"
  389.      INDEX on solicitor to sol_code
  390.      SET talk off
  391.  
  392.  
  393.      Compiling the Application
  394.  
  395.           This application has only two separate programs, although one
  396.      consists of several files.
  397.  
  398.           The following program is used to compile the programs in this
  399.      application, and immediately execute the menu program
  400.  
  401.      COMP entry
  402.      COMP donmenu
  403.      CHAIN donmenu
  404.  
  405.  
  406.      Summary
  407.  
  408.           If this were created for a real customer, instead of as a
  409.      demonstration, a number of additional features would probably be
  410.      added.
  411.  
  412.  
  413.  
  414.                        CHARITY.DOC                                  Page 8
  415.           For example, the three data entry programs -- ENTRY, DONEDIT, and
  416.      SOLEDIT -- should probably allow users to change the current index,
  417.      find records based on the current index, and switch between BROWSE and
  418.      EDIT as shown in the demonstration program EDBROW included on the Info
  419.      distribution disk.
  420.  
  421.           Since ENTRY and DONEDIT require the user to enter records by
  422.      donor and solicitor code numbers, it would also be useful to give
  423.      users a way to BROWSE those data files to check the code numbers.
  424.  
  425.           There are several additional reports that would be useful,
  426.      including the ability to limit the report to specific solicitors
  427.      and/or donors, or groups of them.  Rather than extend the list of
  428.      reports on the main menu, creation of a separate program with its own
  429.      menu of reports would be preferred.
  430.  
  431.           Charities have to produce receipts to donors, donor cards for
  432.      collectors, solicitation cards for solicitors, and solicitation
  433.      letters for the next campaign.  All of these functions can easily be
  434.      done in one program using TEXT for output processing to the printer.
  435.  
  436.           You are invited to run this application, and make these and other
  437.      improvements as a way to improve your programming ability in Info.  By
  438.      the time you have one complete application under your belt, you're a
  439.      genuine Info expert!
  440.  
  441.           Good luck.
  442.