UpperBound PowerScript function
Description
Obtains the upper bound of a dimension of an array.
Syntax
|
1 |
<span>UpperBound</span> ( <span>array</span> {, <span>n</span> } ) |
|
Argument |
Description |
|---|---|
|
array |
The name of the array for which you want |
|
n |
The number of the dimension for which |
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.
Usage
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.
Examples
The following statements illustrate the values UpperBound reports
for fixed–size arrays and for variable-size arrays before
and after memory has been allocated:
|
1 |
integer a[5] |
|
1 |
<span>UpperBound</span>(a)  // Returns 5 |
|
1 |
<span>UpperBound</span>(a,1) // Returns 5 |
|
1 |
<span>UpperBound</span>(a,2) // Returns -1; no 2nd dimension |
|
1 |
|
1 |
integer b[10,20] |
|
1 |
<span>UpperBound</span>(b,1) // Returns 10 |
|
1 |
<span>UpperBound</span>(b,2) // Returns 20 |
|
1 |
|
1 |
integer c[ ] |
|
1 |
<span>UpperBound</span>(c)  // Returns 0; no memory allocated |
|
1 |
c[50] = 900 |
|
1 |
<span>UpperBound</span>(c)  // Returns 50 |
|
1 |
c[60] = 800 |
|
1 |
<span>UpperBound</span>(c)  // Returns 60 |
|
1 |
c[60] = 800 |
|
1 |
c[50] = 700 |
|
1 |
<span>UpperBound</span>(c)  // Returns 60 |
|
1 |
|
1 |
integer d[10 to 50] |
|
1 |
<span>UpperBound</span>(d)  // Returns 50 |
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:
-
Parent – The
parent window of the control that is running the script. -
Menuid – A property of a window whose value
identifies the menu associated with the window. -
Item – A property of a menu that is an
array of items in that menu. If Item is itself a drop-down or cascading
menu, it has its own item array, which can be a fourth qualifier.
The script is:
|
1 |
long i, k, tot1, tot2 |
|
1 |
|
1 |
// Determine how many menu bar items there are. |
|
1 |
tot1 = <span>UpperBound</span>(Parent.Menuid.Item) |
|
1 |
|
1 |
FOR i = 1 to tot1 |
|
1 |
// Find the position of the File item. |
|
1 |
IF Parent.Menuid.Item[i].text = "File" THEN |
|
1 |
MessageBox("Position", & |
|
1 |
"File is in Position "+ string(i)) |
|
1 |
tot2 = <span>UpperBound</span>(Parent.Menuid.Item[i].Item) |
|
1 |
|
1 |
FOR k = 1 to tot2 |
|
1 |
// Find the Update item under File. |
|
1 |
IF Parent.Menuid.Item[i].Item[k].Text = & |
|
1 |
"Update" THEN |
|
1 |
// Disable the Update menu option. |
|
1 |
Parent.Menuid.Item[i].Item[k].Disable() |
|
1 |
EXIT |
|
1 |
END IF |
|
1 |
NEXT |
|
1 |
EXIT |
|
1 |
END IF |
|
1 |
NEXT |