佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > asp 動(dòng)態(tài)數(shù)組 提供Add、Insert、Remove、RemoveAt、Search等方法。

asp 動(dòng)態(tài)數(shù)組 提供Add、Insert、Remove、RemoveAt、Search等方法。

熱門(mén)標(biāo)簽:銀行業(yè)務(wù) 阿里云 服務(wù)器配置 電子圍欄 Linux服務(wù)器 團(tuán)購(gòu)網(wǎng)站 Mysql連接數(shù)設(shè)置 科大訊飛語(yǔ)音識(shí)別系統(tǒng)
復(fù)制代碼 代碼如下:

Class Vector

Private vector_datas()
Private initial_capacity '初始化容量
Private capacity_increment '容量增量
Private element_count '元素?cái)?shù)
Private max_capacity '總?cè)萘?

Private Sub Class_Initialize()
RemoveAll
End Sub

Public Function RemoveAll()
element_count = 0
initial_capacity = 10
capacity_increment = 10
max_capacity = initial_capacity
ReDim vector_datas(initial_capacity)
End Function

Public Property Get Count()
Count = element_count
End Property

Public Property Get Capacity()
Capacity = max_capacity
End Property

Public Property Get InitialCapacity()
InitialCapacity = initial_capacity
End Property

Public Property Get CapacityIncrement()
CapacityIncrement = capacity_increment
End Property

Public Default Property Get Item(index)
If IsObject(vector_datas(index)) Then
Set Item = vector_datas(index)
Else
Item = vector_datas(index)
End If
End Property

Public Function Add(element)
Call Insert(element_count, element)
End Function

Public Function Remove(element)
Dim index
index = Search(element)
RemoveAt(index)
Remove = index
End Function

Public Function RemoveAt(index)
Dim i
For i = index + 1 To element_count - 1 Step 1
Call InternalElement(i - 1, vector_datas(i))
Next
element_count = element_count - 1
If max_capacity - capacity_increment > element_count Then
max_capacity = max_capacity - capacity_increment
ReDim Preserve vector_datas(max_capacity)
End If
End Function

Public Function Search(element)
Dim i
For i = 0 To element_count - 1 Step 1
If vector_datas(i) = element Then
Search = i
Exit Function
End If
Next
Search = -1
End Function

Public Function Insert(index, element)
If index > element_count Then
Err.Raise 20903, "Vector", "Array Index Out Of Bounds.", "", 0
End If
If element_count = 0 Then
Call InternalElement(0, element)
ElseIf index = element_count Then
Call InternalElement(element_count, element)
Else
Dim i
For i = element_count To index + 1 Step -1
Call InternalElement(i, vector_datas(i - 1))
Next
Call InternalElement(index, element)
End If
element_count = element_count + 1
If element_count = max_capacity Then
max_capacity = element_count + capacity_increment
ReDim Preserve vector_datas(max_capacity)
End If
End Function

Public Function SetElementAt(index, element)
If index 0 Or index > element_count - 1 Then
Err.Raise 20903, "Vector", "Array Index Out Of Bounds.", "", 0
End If
Call InternalElement(index, element)
End Function

Private Function InternalElement(index, element)
On Error Resume Next
If IsObject(element) Then
Set vector_datas(index) = element
Else
vector_datas(index) = element
End If
If Err.Number > 0 Then
MsgBox("Vector InternalElement Error: " vbCrLf "Error Source: " Err.Source vbCrLf "Error Number: " Err.Number vbCrLf "Error Description: " Err.Description vbCrLf)
Err.Clear '清除錯(cuò)誤信息
End If
End Function

Private Sub Class_Terminate() '類(lèi)銷(xiāo)毀
Erase vector_datas '釋放數(shù)組占用的內(nèi)存, 將每個(gè)元素都設(shè)為 Nothing
initial_capacity = Empty
capacity_increment = Empty
element_count = Empty
max_capacity = Empty
End Sub

End Class


本文來(lái)自CSDN博客,轉(zhuǎn)載請(qǐng)標(biāo)明出處:http://blog.csdn.net/o1o2o3o4o5/archive/2009/10/20/4703033.aspx
您可能感興趣的文章:
  • asp取得數(shù)組中的最大值的方法
  • asp下使用數(shù)組存放數(shù)據(jù)的代碼
  • asp 得到動(dòng)態(tài)數(shù)組中元素的個(gè)數(shù)
  • asp.net 數(shù)組中字符串替換的幾種方式
  • asp.net 字符串、二進(jìn)制、編碼數(shù)組轉(zhuǎn)換函數(shù)
  • asp.net通過(guò)js實(shí)現(xiàn)Cookie創(chuàng)建以及清除Cookie數(shù)組的代碼
  • asp textarea 多行數(shù)組分割處理方法
  • asp 數(shù)組 重復(fù)刪除函數(shù)(腳本之家增強(qiáng)版)
  • ASP 過(guò)濾數(shù)組重復(fù)數(shù)據(jù)函數(shù)(加強(qiáng)版)
  • ASP 使用Filter函數(shù)來(lái)檢索數(shù)組的實(shí)現(xiàn)代碼
  • asp數(shù)組的使用介紹
  • Asp與JS的數(shù)組和字符串下標(biāo)介紹
  • asp中使用redim、preserve創(chuàng)建動(dòng)態(tài)數(shù)組實(shí)例
  • ASP定義數(shù)組方法的技巧

標(biāo)簽:棗莊 蚌埠 大理 江蘇 廣元 衢州 衡水 萍鄉(xiāng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp 動(dòng)態(tài)數(shù)組 提供Add、Insert、Remove、RemoveAt、Search等方法。》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話(huà)咨詢(xún)

    • 400-1100-266
    仁寿县| 玉环县| 吉林省| 锦屏县| 石棉县| 吴堡县| 崇文区| 天水市| 措美县| 徐闻县| 界首市| 基隆市| 冷水江市| 双桥区| 江门市| 临漳县| 吴川市| 贵南县| 榆树市| 金乡县| 盐亭县| 准格尔旗| 丁青县| 平安县| 咸阳市| 开远市| 北碚区| 仪征市| 龙泉市| 南城县| 娄底市| 奉化市| 永吉县| 曲阜市| 新乐市| 湘潭市| 海宁市| 渝北区| 阿克陶县| 无锡市| 察雅县|