Article ID: 102890
Article Last Modified on 12/3/2003
APPLIES TO
- Microsoft Visual FoxPro 3.0 Standard Edition
- Microsoft FoxPro 2.5b
- Microsoft FoxPro 2.0
- Microsoft FoxPro 2.5b for MS-DOS
This article was previously published under Q102890
SUMMARY
You can display running totals from database fields, or running totals for a particular control break, by using calculated fields in a BROWSE command.
The following example uses the CUSTOMER database and displays the running total of year-to-date purchases (YTDPURCH field) using the file and field names in FoxPro 2.x:
SELECT 0 USE CUSTOMER BROWSE FIELDS CNO, YTDPURCH, RUNNINGYTD=RUNNINGSUM() PROCEDURE RUNNINGSUM m.saverec = RECNO() GO TOP SUM YTDPURCH WHILE RECNO() <= m.saverec TO m.total GO m.saverec RETURN m.total
The same concept can also be applied to display running totals for a particular control break. For example, if we wanted to calculate the running total of year-to-date purchases by company number (CNO), and have an index tag on CNO, the following code could be used:
SELECT 0 USE CUSTOMER SET ORDER TO TAG CNO BROWSE FIELDS CNO, YTDPURCH, RUNNINGSUM = CNOTOT(CNO) FUNCTION CNOTOT PARAMETERS mkey m.saverec = RECNO() SEEK mkey SUM YTDPURCH WHILE CNO=mkey .AND. RECNO()<=m.saverec to m.total GO m.saverec RETURN m.total
Additional query words: VFoxWin FoxDos FoxWin 2.00, 2.50, BROWSE, CALCULATE
Keywords: KB102890