Highlighted Valued Contributor.
516 views

## what is the use of Lbound function in VB?

Hi,

As i know, the value of Lbound for any dimension of array will be zero. So what is the use of it.

I did searching and found out below point, where Lbound found as useful but i didnt understand it.

I would appriciate if someone can explain it to me.

1. Use the LBound function with the UBound function to determine the size of an array.

My question: we can directly use Ubound +1 to get size of an array. what is the mean of above statement?

2.  In below code snnipet,

' Return the lowest subscripts of each dimension a 2-d array.
Dim costs(0 to 10, 1 to 100) As Double
Dim costsLB1 As Integer
Dim costsLB2 As Integer
costsLB1 = LBound( costs, 1 )
costsLB2 = LBound( costs, 2 )

' Now, costsLB1 = 0 and costsLB2 = 1.

My question: what type of array is this (code highlighted in red)? can we declare array like this?

Regards,

1 Solution

Accepted Solutions
Highlighted Honored Contributor.

Lbound, gives you the lower dimension of the array. synatax is lbound( arrayname, dimension)

The example you have provided is used in VBA

By default the lbound for any array is 0, but in the example you have provided

Dim costs(0 to 10, 1 to 100) As Double   => this is a two dimension array

the lbound(Costs,1) is 0 => the lower bound for the first dimension in the cost array

the ubound(Costs,1) is 10 => the ubound for the first dimension in the cost array

the lbound(Costs,2) is 1  => the lower bound for the second dimension in the cost array

the ubound(Costs,2) is 100 => the upper bound for the second dimension in the cost array

Hope this helps. You cannot use this in UFT.

GoScriptLESS(support@scriptlessautomation.com)

2 Replies
Highlighted Micro Focus Expert

hi, there

the syntax is not supported in UFT. It could be just VB, not VBS. I also searched and found the below link:

https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/lbound-function

There you can also see the usage of LBound as the array can be started from non-zero.

Thanks.

James

Highlighted Honored Contributor.

Lbound, gives you the lower dimension of the array. synatax is lbound( arrayname, dimension)

The example you have provided is used in VBA

By default the lbound for any array is 0, but in the example you have provided

Dim costs(0 to 10, 1 to 100) As Double   => this is a two dimension array

the lbound(Costs,1) is 0 => the lower bound for the first dimension in the cost array

the ubound(Costs,1) is 10 => the ubound for the first dimension in the cost array

the lbound(Costs,2) is 1  => the lower bound for the second dimension in the cost array

the ubound(Costs,2) is 100 => the upper bound for the second dimension in the cost array

Hope this helps. You cannot use this in UFT.

GoScriptLESS(support@scriptlessautomation.com)

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.