VBS ArrayList Class vbs中的数组类

时间:2021-05-22

ClassArrayList
Privateitems()
Privatesize

PrivateSubClass_Initialize
size=0
ReDimitems(1)
EndSub

PrivateSubClass_Terminate
items=null
EndSub

PublicFunctionAdd(ByValvalue)
If(size=Ubound(items))ThenEnsureCapacity((size+1))

items(size)=value
size=size+1
Add=size
EndFunction

PublicPropertyGetItem(index)
Item=items(index)
EndProperty

PublicPropertyLetItem(index,vObject)
items(index)=vObject
EndProperty

PropertyGetCount
Count=size
EndProperty


PublicPropertyGetCapacity()
Capacity=Ubound(items)
EndProperty

PublicPropertyLetCapacity(value)
If(value<>Ubound(items))Then
If(value<size)ThenErr.Rise6

If(value>0)Then
ReDimPreserveitems(value)
Else
ReDimPreserveitems(3)
EndIf
EndIf
EndProperty

PrivateSubEnsureCapacity(ByValmin)
If(Ubound(items)<min)Then
Dimnum1:num1=IIf((Ubound(items)=0),4,(Ubound(items)*2))
If(num1<min)Thennum1=min
Capacity=num1
EndIf
EndSub


PrivateFunctionIIf(j,r1,r2)
IF(j)Then
IIf=r1
Else
IIf=r2
EndIF
EndFunction

EndClass


示例:

Dimal:Setal=newArrayList
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)

Fori=0Toal.Count-1
w("Index"&i&":"&al.Item(i))
Next

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

Subw(o)
Response.Write(o&"<br/>")
EndSub

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章