中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > LOTUS > 开发心得
作collection功能
作者:未知 时间:2005-07-22 13:39 出处:Lotus中文技术站 责编:chinaitpower
              摘要:作collection功能
写完了就没有意思了,没有仔细测,很明显的两处bug也没有改 :)

Option Public
Option Explicit
Option Compare Nocase

Const ArrayTop=400


Public Class MyCollection

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 本lib实现collection功能
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Private mCount As Integer '所有的已经分配空间数量
Private mCountUnused As Integer '已分配空间中被回收部分数量
Private mCountUsed As Integer '已分配空间中使用部分数量
Private mIndexUsed() As Integer 'Index序列号
' Private mKeys() As String 'key键值,使用keys方式,主要为建立dictionary方式
Private mObjects() As Variant '存储分配空间
Private mIndexUnused() As Integer '被回收的序列号空间

Public Sub New()
mCount=0
mCountUnused=0
Redim mIndex(0)
Redim mKeys(0)
Redim mObjects(0)
Redim mIndexUnused(0)
End Sub

Public Property Get Member(intIndex As Integer)
Set Member=mObjects(mIndexUsed(intIndex))
End Property

Public Property Set Member(intIndex As Integer)
Set mObjects(mIndexUsed(intIndex))=Member
End Property

Public Function AddMember(vMember,intIndex As Integer)
Dim CurPos As Integer '如果待插入点在当前的范围之外,那么,将它插入在最后
Dim i
If intIndex<1 Or intIndex>mCountUsed Then 
CurPos=mCountUsed+1
Else
CurPos=intIndex
End If
If mCountUnused>0 Then
'从回收的空间分配
Set mObjects(mIndexUnused(mCountUnused))=vMember
For i=mCountUsed To CurPos Step -1
mIndexUsed(i+1)=mIndexUsed(i)
Next
mIndexUsed(CurPos)=mIndexUnused(mCountUnused)
mCountUnused=mCountUnused-1
mCountUsed=mCountUsed+1
Else
'新分配空间
If mCount Mod ArrayTop=0 Then
'如果空间已经使用完毕,创建新的空间
Redim Preserve mIndexUsed(mCount+ArrayTop)
Redim Preserve mObjects(mCount+ArrayTop)
Redim Preserve mIndexUnused(mCount+ArrayTop)
End If
For i=mCountUsed To CurPos Step -1
mIndexUsed(i+1)=mIndexUsed(i)
Next
mCountUsed=mCountUsed+1
mCount=mCount+1
Set mObjects(mCountUsed)=vMember
mIndexUsed(CurPos)=mCountUsed
End If
End Function

Public Function DelMember(intIndex As Integer)
If intIndex<1 Or intIndex>mCountUsed Then
'如果要删除的序列值在范围之外,则取消本操作
Exit Function
End If
Dim i
mCountUnused=mCountUnused+1
mIndexUnused(mCountUnused)=mIndexUsed(intIndex)
For i= intIndex To mCountUsed
mIndexUsed(i)=mIndexUsed(i+1)
Next
mCountUsed=mCountUsed-1
End Function

Public Property Get Count As Integer
Count=mCountUsed
End Property
End Class
关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有