upperbound 函数的作用是什么?

pb_bulletsoft 2003-04-04 04:22:45
1
...全文
874 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
meteor_wyj 2003-04-04
  • 打赏
  • 举报
回复
取数据的维数呀
dancer 2003-04-04
  • 打赏
  • 举报
回复
返回数组的维数,一般是用在没有定义维数的数组

string a[]

然后在中间对a进行了赋值操作

for i=1 to upperbound(a)
....
next

tchatcha 2003-04-04
  • 打赏
  • 举报
回复
取数组上限
young52010 2003-04-04
  • 打赏
  • 举报
回复
都知道函数了,直接查PB的帮助不就行了。
Description

Obtains the upper bound of a dimension of an array.

Syntax

UpperBound ( array {, n } )

Argument Description
array 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 value

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.

EXAMPLE

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

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 dropdown or cascading menu, it has its own item array, which can be a fourth qualifier.

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.
Parent.Menuid.Item[i].Item[k].Disable()
EXIT
END IF
NEXT
EXIT
END IF

NEXT

743

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 脚本语言
社区管理员
  • 脚本语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧