Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement array classes in ArrayList Class vbs by VBS

Shulou Source: shulou.com Published: 2022-06-03 06:02:35 10月05日 Update

This article mainly shows you "VBS how to achieve array classes in ArrayList Class vbs", the content is easy to understand, clear, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "VBS how to achieve array classes in ArrayList Class vbs" this article.

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 & "")

End Sub

These are all the contents of the article "how VBS implements array classes in ArrayList Class vbs". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Arrays content articles learning help easy to understand more organization knowledge examples editing industry information information channels channels research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi Docker vpn Microsoft