Sybase Technical Library - Product Manuals Home
[Search Forms] [Previous Section with Hits] [Next Section with Hits] [Clear Search] Expand Search

Upper [Table of Contents] Which

PowerScript Reference (Online Only)

[-] Part 2: Statements, Events, and Functions
[-] Chapter 10 PowerScript Functions
[-] UpperBound



Obtains the upper bound of a dimension of an array.


UpperBound ( array {, n } )




The name of the array for which you want the upper bound of a dimension

n (optional)

The number of the dimension for which you want the upper bound. The default is 1

Return values

Long. Returns the upper bound of dimension n of array. If n is greater than the number of dimensions of the array, UpperBound returns -1. If any argument's value is null, UpperBound returns null.


For variable-size arrays, memory is allocated for the array when you assign values to it. UpperBound returns the largest value that has been defined for the array in the current script. Before you assign values, the lower bound is 1 and the upper bound is 0. For fixed arrays, whose size is specified when it is declared, UpperBound always returns the declared size.


Example 1

The following statements illustrate the values UpperBound reports for fixed-size arrays and for variable-size arrays before and after memory has been allocated:

integer a[5]
UpperBound(a)    // Returns 5
UpperBound(a,1)  // Returns 5
UpperBound(a,2)  // Returns -1; no 2nd dimension
integer b[10,20]
UpperBound(b,1)  // Returns 10
UpperBound(b,2)  // Returns 20
integer c[ ]
UpperBound(c)   // Returns 0; no memory allocated
c[50] = 900
UpperBound(c)   // Returns 50
c[60] = 800
UpperBound(c)   // Returns 60
c[60] = 800
c[50] = 700
UpperBound(c)   // Returns 60
integer d[10 to 50]
UpperBound(d)   // Returns 50

Example 2

This example determines the position of a menu bar item called File, and if the item has a cascading menu with an item called Update, disables the Update item. The code could be a script for a control in a window.

The code includes a rather complicated construct: Parent.Menuid.Item. Its components are:

Example 3

The script is:

long i, k, tot1, tot2
// Determine how many menu bar items there are.
tot1 = UpperBound(Parent.Menuid.Item)
FOR i = 1 to tot1
      // Find the position of the File item.
      IF Parent.Menuid.Item[i].text = "File" THEN
         MessageBox("Position", &
            "File is in Position "+ string(i))
         tot2 = UpperBound(Parent.Menuid.Item[i].Item)
         FOR k = 1 to tot2
            // Find the Update item under File.
            IF Parent.Menuid.Item[i].Item[k].Text = &
               "Update" THEN
               // Disable the Update menu option.
            END IF
      END IF

See also

Upper [Table of Contents] Which