Sequence Object

This object allows a sequence to be created.  Each object is its own sequence.  For example, tables & figures could have their own sequence.

The sequence can be prefixed with a prefix.  This prefix could be a chapter number.  If no prefix is used, NULL ("") must be passed to the constructor.

For cross referencing, a tag can be passed in to .next().  The tag is is associated with the value.  The value can be retrieved.

Object Definition

<script language="JavaScript1.1">
<!--
  //Purpose: provide an incrementing counter a specific value can be tagged
  //         for cross reference.
  //
  //Usage:   obj = new Counter("Opt_prefix")- Constructor for the object
  //         val = obj.next("opt_tag")      - Creates a new number, attaches tag if given
  //                                        - returns the same sequence num that getNum() does.
  //         val = obj.getNum("tag");       - Returns the sequence number (including prefix)
  function Sequence(prefix) {
    this.cur       = 0;
    this.pre       = prefix;
    this.next      = Next;
    this.getNum    = GetNum;
    this.tag       = new Array();
  }

  //Purpose: create a new value in the sequence (see Sequence object)
  function Next(name) {
    this.cur++;
    if (name != "") {
      this.tag[this.cur] = name;
    }
    return (this.pre + this.cur);
  }

  //Purpose: returns the sequence number for a given tag (see Sequence object)
  function GetNum(tag) {
    for (var i = 1;  i < this.tag.length;  i++) {
      if (tag == this.tag[i])  return(this.pre + i);
    }
    return (this.pre + "?");
  }
//-->
</script>

Example Usage

Code Output
<script language="JavaScript1.1"> 
<!--
  with (document) {
    var seq = new Sequence("");

    seq.next("");
    var seq1 = new Sequence("");

    write("No prefix<br>");
    write(seq1.next() + "<br>");
    write(seq1.next() + "<br>");
    write(seq1.next() + "<br>");

    seq.next("seq2");
    var seq2 = new Sequence(seq.getNum("seq2") + "-");

    write("<br>Prefix from value in an other sequence<br>");
    write(seq2.next() + "<br>");
    write(seq2.next() + "<br>");
    write(seq2.next() + "<br>");
  }
// --> 
</script>



Last Updated: $Date: 2002/03/25 06:35:54 $ GMT ($Revision: 1.5 $)