Count sort keys |
This counts the number of unique sort headers or footers in a report, and puts the total into a report footer. It can use either a sort footer box or a sort header box. The sort header/footer box and the report footer box need to be given the same script names as the ones used in the script. |
Script Language: JavaScript | For use with: DB/TextWorks DB/SearchWorks DB/Text Run-time | Requires at least version 4.1 |
// If you have assigned different script names to the sort
// header/footer box and the report footer box in your form,
// change the names in these two variables to match:
var sortBoxName = "sortfoot"; // sort footer box name
var totalBoxName = "reportfoot"; // report footer box name
// additional global variables
var sortCount = 0; // number of unique sort keys
var lastKey = ""; // text of last unique sort key
function onReportInitialize()
{
sortCount = 0; // initialize sortCount to zero
lastKey = ""; // initialize lastKey to empty
}
function onRecordOpen()
{
var sortBox; // box named sortBoxName
var totalBox; // box named totalBoxName
var sortBoxContent; // content of sortBox
var totalText; // text in report footer box
// check for existence of boxes named above,
// stopping if both are not found
sortBox = Form.boxes(sortBoxName);
if (!sortBox)
return;
totalBox = Form.boxes(totalBoxName);
if (!totalBox)
return;
// count unique sortBoxName boxes
sortBoxContent = sortBox.content;
if (sortBoxContent != "") // do not count empty boxes
{
// check for new key
// if new, increment count and save key text
// to compare with the next key
if (sortBoxContent != lastKey)
{
sortCount = sortCount + 1;
lastKey = sortBoxContent;
}
}
// Append the running total to the contents of the report
// footer box. That box only appears in the last record,
// at which point the total will be accurate.
totalText = totalBox.content + " " + sortCount.toString() ;
totalBox.content = totalText;
}
|
Notes: This script assumes that the report footer box contains fixed text such as "Total keys:". It appends a space and then the count to this text. If you want a different format for this information, modify the end of the script accordingly. | Submitted by Inmagic Staff on 11/30/2000 |