Do you find this script useful?
Yes
No
Comments?
Numbering records for each sort key
If you use the RECORD NUMBER variable in a form, the numbering continues across sort keys (e.g., when sorting by vendor, if the first vendor listed 5 journal titles, the title listing for the second vendor would start with 6, rather than 1). Often it would be useful to restart the numbering at 1 when the sort key changes.
Script Language: JavaScript For use with:
DB/TextWorks
Requires at least version 4.1
// If you have assigned different script names to the sort
// header box and the box you want to number in your form,
// change the names in these two variables to match:

var sortBoxName = "sorthead";  // sort header box name
var numBoxName = "numbox";     // box for record numbering

// additional global variables

var recNumber; // record number counter
var lastKey;   // text of last unique sort key

function onFormOpen()
{
  recNumber = 0;   // initialize record counter to zero
  lastKey = "";    // initialize lastKey to empty
}

function onReportInitialize()
{
  recNumber = 0   // initialize record counter to zero
  lastKey = "";   // initialize lastKey to empty
}

function onRecordOpen()
{
  var sortBox;        // box named sortBoxName
  var numBox;         // box named numBoxName
  var sortBoxContent; // content of sortBox
  var numText;        // text in record counter box

  // check for existence of boxes named above,
  // stopping if both are not found
  sortBox = Form.boxes(sortBoxName);
  if (!sortBox)
    return;
  numBox = Form.boxes(numBoxName);
  if (!numBox)
    return;

  sortBoxContent = sortBox.content;
  if (sortBoxContent != "")
      {
      // check for new key
      if (sortBoxContent != lastKey)
        {
//        Application.message(sortBoxContent + "\nrecNumber: " + recNumber);
        recNumber = 1;
        lastKey = sortBoxContent;
//        Application.message(sortBoxContent + "\nrecNumber: " + recNumber);
        }
      else
        {
        recNumber = recNumber + 1;
        }
      }
    numText = recNumber.toString() + ". " + numBox.content;
    numBox.content = numText;
}
Notes: The record numbering is completely handled by the script. There should not be a RECORD NUMBER variable used in the form.
Submitted by Inmagic Staff on 15-May-2001 16:14

Powered by DB/Text WebPublisher, from Inmagic WebPublisher PRO