R6 has some improvements and enhancements to LotusScript, and since then, the interface of the Notes object has been supplemented and updated, but the language itself has not changed. Those improvements include the addition of useful functions such as arraygetindex and Arrayunique. In programming practice, however, there are some operations lotusscript that do not provide native functions, but can basically be written by themselves. The constants used in the following functions are defined in LSCONST.LSS or LSERR.LSS, and are appended before the script
%INCLUDE"LSCONST.LSS"
%INCLUDE"LSERR.LSS"
Determines whether an array contains an element.
[VB]View Plaincopy
- %REM
- Checks If an array contains a value.
- The Arraygetindex function returns null if the value is not found.
- %end REM
- Public Function arraycontains (source As Variant, value as variant) as Boolean
- ' The data type of source is not checked intentionally
- Arraycontains= notIsNull (Arraygetindex (source,value))
- End Function
The array in LotusScript can have up to eight dimensions (dimension), and the following function takes advantage of a run-time error (run-time error) Errsubscriptoutofrange to obtain the dimension.
[VB]View Plaincopy
- ' Returns the number of an array ' s dimensions
- Function arraydimension (array as Variant) as Integer
- If not IsArray (array) Then
- Arraydimension=0
- Exit Function
- End If
- on Error errsubscriptoutofrange GoTo RESULT
- Dim D As Integer, lb as integer
- For d=1 to 9
- Lb=lbound (Array, D)
- Next
- RESULT:
- Arraydimension=d-1
- Exit Function
- End Function
Returns the size of a multidimensional array, that is, the number of all elements.
[VB]View Plaincopy
- Function ArraySize (array as Variant) as Integer
- If not IsArray (array) Then
- Arraysize=0
- Exit Function
- End If
- Arraysize=1
- Dim D as Integer
- D=arraydimension (Array)
- Dim i as Integer
- For I=1 to D
- arraysize=arraysize* (UBound (array, i)-lbound (array,i) +1)
- Next
- End Function
Determine the "shape" of two arrays, i.e. whether the dimensions are the same as the upper and lower bounds of each dimension. This function is useful when comparing arrays for equality in the future.
[VB]View Plaincopy
- Function arrayboundsequals (A1 as Variant, A2 as variant) as Boolean
- If (notIsArray (A1)) Or (notIsArray (A2) ) Then
- arrayboundsequals=False
- Exit Function
- End If
- Dim d1 As Integer, D2 as integer
- D1=arraydimension (A1)
- D2=arraydimension (A2)
- If d1<>d2 Then
- arrayboundsequals=False
- Exit Function
- End If
- Dim D as Integer
- For d=1 to D1
- If LBound (A1) ><lbound (A2) Or UBound (A1) ><ubound (A2) Then
- arrayboundsequals=False
- Exit Function
- End If
- Next
- arrayboundsequals=True
- End Function
Converts a multidimensional array into a one-dimensional array. This function is also used to compare the equality of two arrays.
[VB]View Plaincopy
- Function arraytoonedimension (array as variant) as variant
- If not IsArray (array) Then
- Call SetValue (arraytoonedimension, array)
- Exit Function
- End If
- Dim D as Integer
- D=arraydimension (Array)
- If d=1 Then
- Arraytoonedimension=array
- Exit Function
- End If
- Dim size as Integer
- Size=arraysize (Array)
- Dim result () as Variant
- ReDim result (size-1)
- Dim i as Integer
- ForAll e in array
- Result (i) =e
- I=i+1
- End ForAll
- Arraytoonedimension=result
- End Function
The array functions in LotusScript.