Summation of Transaction Fields on a Form Summary: This technote explains how to total all records, or a filtered subset, of a transaction field in a file, when all of the records don't fit in the transaction block defined on the form. [This example does this by creating two example files and a form.] Consider the following two file definitions: File 1 : Master File 2 : Detail SSN Name Total SSN Course# Marks 123 Bob 123 Phy1 12 234 Steve 123 Phy2 13 345 Larry 123 Phy3 11 123 Cis1 10 123 Cis 2 8 234 Phy1 15 234 Phy2 17 234 Phy2 10 345 Math1 19 345 Arts1 10 Field definitions SSN in both files is a Numeric Integer. Name.Master and Course#.Detail are text fields. Total.Master and Marks.Detail are Numeric Integers. Master & Detail are linked on the SSN field. Now you need to design a form. This form should list each student's social security number and name from the Master file and all the courses and respective marks in those courses from the Detail file. In addition to that you also want to display the total of all the marks for a given student at the bottom of the marks list on the form and store that value in the Total.Master field. Begin by placing all the fields on the form and creating transaction lines. The form looks similar to the one shown below. When the user pushes the 'TOTAL' push button, the form is updated with the calculation of the total marks for the student and stores the value in the Total.Master field. The command for the 'TOTAL' push button is as follows: REM Make the Detail file the current file and select the current record FILE "Detail" SELECT CURRENT REM Assign the SSN from Master to a variable a%% a%% = SSN.Master REM Check to see if there are any corresponding records in the Detail REM Proceed only if there are any records in Detail SELECT KEY a%% FILE "Detail" IF NOT FOUND("") THEN END ELSE REM Select records from the Detail file for the corresponding SSN REM Summarize Marks to a variable Temp% WHILE NOT EOF("Detail") Temp%=Temp%+Marks.Detail SELECT DUPLICATE WEND REM Store the summarized value in Total.Master field SELECT KEY a%% FILE "Master" Total.Master = Temp% STORE FILE "Master" FILE "Master" SELECT FORM KEY a%% REM Refresh form to display the Total.Master field. FORM In the above program, the lines starting with REM are remarks. The remarks and the spaces between lines are added for your benefit. They could be ignored while using the code in your actual program. The field names and file names should be replaced by your own field names and file names. Program: Superbase Versions: 1.3x Date: April 21, 1993