86. array functions in Lotus script, Lotus script Array

Source: Internet
Author: User

86. array functions in Lotus script, Lotus script Array

R6 has some improvements and enhancements to Lotus script. Since then, the Notes object interfaces have been supplemented and updated, but the language has not changed. Those improvements include adding useful functions such as ArrayGetIndex and ArrayUnique. However, in programming practice, some operations on arrays by LotusScript do not provide native functions. Fortunately, they can basically be compiled by themselves. The constants used in the following functions are defined in lsconst. lss or lserr. lss.

% INCLUDE "lsconst. lss"

% INCLUDE "lserr. lss"

Determines whether an array contains an element.

%REMChecks if an array contains a value.The ArrayGetIndex function returns null if the value is not found.%END REMPublic Function ArrayContains(source As Variant, value As Variant) As Boolean'the data type of source is not checked intentionallyArrayContains=Not IsNull(ArrayGetIndex(source,value))End Function

The arrays in Lotus script can have a maximum of eight dimensions. The following function uses the run-time error ErrSubscriptOutOfRange to obtain the dimension.

'Returns the number of an array's dimensionsFunction ArrayDimension(array As Variant) As IntegerIf Not IsArray(array) ThenArrayDimension=0Exit Function End IfOn Error ErrSubscriptOutOfRange GoTo RESULTDim d As Integer, lb As Integer  For d=1 To 9lb=LBound(array, d)NextRESULT:ArrayDimension=d-1Exit Function End Function

Returns the size of a multi-dimensional array, that is, the number of all elements.

Function ArraySize(array As Variant) As IntegerIf Not IsArray(array) ThenArraySize=0Exit Function End IfArraySize=1Dim d As Integerd=ArrayDimension(array)Dim i As IntegerFor i=1 To dArraySize=ArraySize*(UBound(array, i)-LBound(array,i)+1)NextEnd Function

Determine the shape of the two arrays, that is, whether the dimension is the same as the upper and lower limits of each dimension. This function can be used to compare whether arrays are equal in the future.

Function ArrayBoundsEquals(a1 As Variant, a2 As Variant) As BooleanIf (Not IsArray(a1)) Or (Not IsArray(a2)) ThenArrayBoundsEquals=FalseExit Function End IfDim d1 As Integer, d2 As Integerd1=ArrayDimension(a1)d2=ArrayDimension(a2)If d1<>d2 ThenArrayBoundsEquals=FalseExit FunctionEnd IfDim d As IntegerFor d=1 To d1If LBound(a1)><LBound(a2) Or UBound(a1)><UBound(a2) ThenArrayBoundsEquals=FalseExit FunctionEnd IfNextArrayBoundsEquals=True End Function

Converts a multi-dimensional array to a one-dimensional array. This function is also used to compare whether two arrays are equal.

Function ArrayToOneDimension(array As Variant) As VariantIf Not IsArray(array) ThenCall SetValue(ArrayToOneDimension, array)Exit Function End IfDim d As Integerd=ArrayDimension(array)If d=1 ThenArrayToOneDimension=arrayExit FunctionEnd IfDim size As Integersize=ArraySize(array)Dim result() As VariantReDim result(size-1)Dim i As Integer ForAll e In arrayresult(i)=ei=i+1End ForAllArrayToOneDimension=resultEnd Function





Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.