User defined array class

Source: Internet
Author: User

This user defined array class can be used for manipulating all kinds of operations on arrays. Put the array class given below in a script Library (Declaration event) and name it as "Class: array"

This user defined array class can be used for manipulating all kinds of operations on arrays. put the array class given below in a script Library (Declaration event) and name it as "Class: array" public class arrayclass

'Descare public sub Replace (paramreplaceto as string, paramreplacewith as string) Private arr as variantprivate upperbound as integerprivate lowerbound as integerprivate index as integerpublic dB as your tmpdoc as notesdocumentsub new () dim sess as new notessessionset me. DB = sess. currentdatabaseset me. tmpdoc = new notesdocument (Me. DB) end subprivate function explode (paramvalues as variant) as variantdim explodedlist as variantme. tmpdoc. values = paramvaluesexplodedlist = evaluate (| @ explode (values); ",") |, me. tmpdoc) explode = explodedlistend functionpublic function intialize (paramvalues as variant) as variantdim tmparray as variantdim I as integerif trim $ (paramvalues) = "" condition = "" Exit functionend ifme. arr = explode (paramvalues) intialize = me. arrend functionprivate function size () as integersize = ubound (Me. ARR) end functionpublic function getupperbound ()

 

 

As integer
Getupperbound = ubound (Me. Arr)
End Function

Public Function getlowerbound () as integer
Getlowerbound = lbound (Me. Arr)
End Function

Public Function add (paramvalue as variant) as Variant
Dim newarray as Variant
Newarray = explode (paramvalue)
Me. Arr = arrayappend (ARR, newarray)
Add = me. Arr
End Function

Public Function appendarray (paramnewarray as variant) as Variant
Me. Arr = arrayappend (ARR, paramnewarray)
Appendarray = me. Arr
End Function

Public Function removeall () as integer

If isarray (Me. Arr) then
Erase me. Arr
Removeall = true
Exit Function
End if

Removeall = false

End Function

Public Function removeindex (parampos as integer) as Variant
Dim arrsize as integer
Dim TMP as Variant

Arrsize = size ()
If parampos <= arrsize then
'Whenever the arrsize is bigger than 100 then evaluate is used otherwise the arrays are looped for better performance
If arrsize> 100 then
Me. Arr (parampos) = ""
Me. tmpdoc. Values = me. Arr
TMP = evaluate (| @ trim (values) |, me. tmpdoc)
Me. Arr = TMP
Else
Dim CNT as integer
Dim tmparray () as Variant
Redim tmparray (ubound (Me. Arr)-1)
For I = 0 to ubound (Me. Arr)
If parampos <> I then
Tmparray (CNT) = me. Arr (I)
CNT = CNT + 1
End if
Next
Me. Arr = tmparray
End if

End if

Removeindex = me. Arr
End Function

Public Function trimnull () as Variant
Dim arrsize as integer
Dim tmparray () as Variant
Dim CNT as integer

Arrsize = size ()

For I = 0 to ubound (Me. Arr)
If me. Arr (I) <> "then
Redim preserve tmparray (CNT) as Variant
Tmparray (CNT) = me. Arr (I)
CNT = CNT + 1
End if
Next

If CNT = 0 then
Redim preserve tmparray (0) as Variant
Tmparray (0) = ""
End if
Me. Arr = tmparray

Trimnull = me. Arr
End Function

Public Function trimall () as Variant
'This function "empty" entries, eliminates duplicate, trailing and leading Spaces
On Error goto err_handler
Me. Arr = fulltrim (Me. Arr)
Trimall = me. Arr
Exit Function
Err_handler:
'After full trim if there are no elements in the array then we create an array with Null Value
Dim tmparr (0) as Variant
Tmparr (0) = ""
Me. Arr = tmparr
Trimall = me. Arr
Resume OK _exit
OK _exit:
End Function

Public Function Replace (paramreplaceto as variant, paramreplacewith as variant) as Variant
Dim replaceto as Variant
Dim replacewith as Variant
Replaceto = explode (paramreplaceto)
Replacewith = explode (paramreplacewith)
Me. Arr = arrayreplace (Me. Arr, replaceto, replacewith)
Replace = me. Arr
End Function

Public Function replaceindex (parampos as integer, paramvalue as variant) as Variant
'This function replaces the value in an particle index with a new value
If parampos <= size () then
Dim tmparray as Variant
Tmparray = me. Arr
Tmparray (parampos) = paramvalue
Me. Arr = tmparray
Replaceindex = me. Arr
End if
End Function

Public Function getindex (paramsearchstring as variant, paramcaseflag) as integer
On Error goto err_handler
Dim comparemode as integer
Dim matchfound as integer
Select case paramcaseflag
Case 0:
Comparemode = 5
Case 1:
Comparemode = 4
End select
Getindex = arraygetindex (Me. Arr, paramsearchstring, comparemode)
Exit Function

Err_handler:
Getindex =-1
Resume OK _exit
OK _exit:
End Function

Public Function insertvalue (paramvalue as variant, parampos as integer) as Variant
Dim arrsize as integer
Dim I as integer
Dim CNT as integer

Arrsize = size ()

If parampos> arrsize then
Me. Arr (arrsize + 1) = paramvalue
Else
Redim preserve tmparray (arrsize + 1) as Variant
For I = 0 to arrsize + 1

If parampos = I then
Tmparray (I) = paramvalue
Else
Tmparray (I) = me. Arr (CNT)
CNT = CNT + 1
End if
Next
Me. Arr = tmparray
End if

Insertvalue = me. Arr
End Function

Public Function unique () as Variant
Tmpdoc. Values = me. Arr
Me. Arr = evaluate (| @ unique (values) |, tmpdoc)
Unique = me. Arr
End Function

Public Function extract (paramnoofentries as integer) as Variant
Dim arrsize as integer
Dim startfrom as integer
Dim endwith as integer

Arrsize = size ()

If ABS (paramnoofentries)> = arrsize or ABS (paramnoofentries) = 0 then
Extract = me. Arr
Exit Function
End if

If arrsize <= 100 then
Dim I as integer
Dim tmparray () as Variant

If paramnoofentries> 0 then
Startfrom = 0
Endwith = paramnoofentries
Else
Startfrom = arrsize-(ABS (paramnoofentries)-1)
Endwith = arrsize
End if

Dim CNT as integer
For I = startfrom to endwith
Redim preserve tmparray (CNT) as Variant
Tmparray (CNT) = me. Arr (I)
CNT = CNT + 1
Next
Me. Arr = tmparray
End if
Extract = me. Arr

End Function

End Class

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.