Array Action Class

Source: Internet
Author: User

Option Explicit

Class CARR
Private tmin '//min value Thismin
Private TMax '//MAX value
Private tstr '//array string
Private tsortstr '//Sort string, avoid multiple sort operations when working on the same array string
Private tlength '//number of elements

Private Sub Class_Initialize
Tmin =0
TMax =0
Tstr = "0"
Tlength =0
Tsortstr= ""
End Sub

'//Get the minimum value
Property Get Cmin
If tmin=0 Then
Dim SSTR
If tsortstr= "" Then
Sstr=split (Csort, ",")
Else
Sstr=split (Tsortstr, ",")
End If
TMIN=SSTR (0)
End If
Cmin=tmin
End Property

'//Get maximum value
Property Get CMax
If tmax=0 Then
Dim SSTR
If tsortstr= "" Then
Sstr=split (Csort, ",")
Else
Sstr=split (Tsortstr, ",")
End If
Tmax=sstr (Ubound (SSTR))
End If
Cmax=tmax
End Property

Property Get Length
If tstr= "" Or tstr=0 Then
Length =0
Else
Tlength =ubound (Split (Tstr, ",")) +1
Length =tlength
End If
End Property

'//Assign array string to property
Property Let Srcstr (str)
If str= "" Then
Tstr= "0"
Else
Tstr=str
End If
End Property

'//Sort, reverse
Public Function Csort
Dim Arr,i
Redim Arr (Ubound (Split (Tstr, ","))
Dim Tmp,j
For i=0 to Ubound (ARR)
ARR (i) =cdbl (Split (Tstr, ",") (i))
Next
For i= 0 to Ubound (ARR)
For J=i+1 to Ubound (ARR)
If ARR (i) <arr (j) Then
TMP =arr (i)
ARR (i) =arr (j)
ARR (j) =tmp
End If
Next
Next
Tsortstr=join (ARR, ",")
Csort=tsortstr
End Function
   
'//Order
Public Function CSORTASC
Dim Tmp,i,arr
If tsortstr= "" Then
Tmp=csort
Else
Tmp=tsortstr
End If
Redim Arr (Ubound (Split (TMP, ","))
Arr=split (TMP, ",")
For i= Ubound (ARR) to 0 Step-1
CSORTASC=CSORTASC & Arr (i) & ","
Next
Csortasc=left (Csortasc,len (CSORTASC)-1)
End Function

"//At the end of the additive element
Public Function AddItem (str)
If tstr= "" "OR tstr=" 0 "Then
Tstr=str
Else
Tstr=tstr & "," & Str
End If
Tmin =0
TMax =0
Tsortstr= ""
Tlength =tlength + 1
AddItem =tstr
End Function

'//Front plus element
Public Function Additembefore (str)
If tstr= "" "OR tstr=" 0 "Then
Tstr=str
Else
Tstr=str & "," & Tstr
End If
Tmin =0
TMax =0
Tsortstr= ""
Tlength =tlength + 1
Additembefore=tstr
End Function

'//removing elements
Public Function RemoveItem (str)
Tstr =replace ("," & Tstr & ",", "," & Str & ",", ",")
Tstr =mid (Tstr,2,len (TSTR)-2)
Tmin =0
TMax =0
Tsortstr=replace ("," & Tsortstr & ",", "," & Str & ",", ",")
Tsortstr=mid (Tsortstr,2,len (TSORTSTR)-2)
Tlength =0
Removeitem=tstr
End Function

'//Add element at index position
Public Function Additemi (INDEX,STR)
If Index>=length Then
AddItem (str)
Exit Function
End If
If index<=0 Then
Additembefore (str)
Exit Function
End If
         
Dim Arr,i,tmps
Redim Arr (Ubound (Split (Tstr, ","))
Arr=split (Tstr, ",")
For I=0 to Index-1
Tmps=tmps & Arr (i) & ","
Next
Tmps=tmps & str & ","
For I=index to Ubound (ARR)
Tmps=tmps & Arr (i) & ","
Next
Tmps =left (Tmps,len (tmps)-1)
Tstr =tmps
Tsortstr= ""
Tlength =tlength+1
Tmin =0
TMax =0
Additemi=tstr
End Function

'//remove element at index position
Public Function Removeitemi (index)
If index>=length Or index<=0 Then
Exit Function
End If
         
Dim Arr,i,tmps
Redim Arr (Ubound (Split (Tstr, ","))
Arr=split (Tstr, ",")
For i=0 to Ubound (ARR)
If i<>index Then Tmps=tmps & Arr (i) & ","
Next
Tmps=tmps & str & ","
Tmps =left (Tmps,len (tmps)-1)
Tstr =tmps
Tsortstr= ""
Tlength =0
Tmin =0
TMax =0
Removeitemi=tstr
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.