The array class _vbs in the VBS ARRAYLIST class VBS

Source: Internet
Author: User
Class ArrayList
Private items ()
Private size

Private Sub Class_Initialize
Size = 0
ReDim items (1)
End Sub

Private Sub Class_Terminate
Items = null
End Sub

Public Function Add (ByVal value)
If (size = Ubound (items)) Then ensurecapacity ((size + 1))

Items (size) = value
size = size + 1
ADD = Size
End Function

Public Property Get Item (Index)
Item = Items (index)
End Property

Public Property Let Item (Index, Vobject)
Items (Index) = Vobject
End Property

Property Get Count
Count = Size
End Property


Public Property Get Capacity ()
Capacity = Ubound (items)
End Property

Public Property Let Capacity (value)
If (Value <> Ubound (items)) Then
If (Value < size) Then Err.rise 6

If (Value > 0) Then
ReDim Preserve Items (value)
Else
ReDim Preserve Items (3)
End If
End If
End Property

Private Sub ensurecapacity (ByVal min)
If (Ubound (items) < min) Then
Dim num1:num1 = IIf (Ubound (items) = 0), 4, (Ubound (items) * 2))
If (Num1 < min) Then num1 = min
Capacity = NUM1
End If
End Sub


Private Function IIf (J, R1, R2)
IF (j) Then
IIf = R1
Else
IIf = R2
End IF
End Function

End Class


Example:

Dim Al:set al = new ArrayList
Al. ADD (1)
Al. ADD (2)
Al. ADD (3)
Al. ADD (4)
Al. ADD (5)
Al. ADD (6)
Al. ADD (7)
Al. ADD (8)
Al. ADD (9)
Al. ADD (10)

For i = 0 to al. Count-1
W ("Index" & I & ":" & al. Item (i))
Next

W ("Count:" & al. Count)
W ("Capacity:" & al. Capacity)

Sub W (o)
Response.Write (O & "<br/>")
End Sub

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.