clsDBbases.cls
Upload User: czxfzx
Upload Date: 2015-02-25
Package Size: 749k
Code Size: 3k
Development Platform:

Visual Basic

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsDBbases"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Collection" ,"clsDBbase"
  16. Attribute VB_Ext_KEY = "Member0" ,"clsDBbase"
  17. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  18. Option Explicit
  19. '局部变量,保存集合
  20. Private mCol As Collection
  21. Public Function Find(Optional lngID As Long = -1) As clsDBbases
  22. End Function
  23. Public Function Add(Optional sKey As String) As clsDBbase
  24.     '创建新对象
  25.     Dim objNewMember As clsDBbase
  26.     Set objNewMember = New clsDBbase
  27.     '设置传入方法的属性
  28.     If Len(sKey) = 0 Then
  29.         mCol.Add objNewMember
  30.     Else
  31.         mCol.Add objNewMember, sKey
  32.     End If
  33.     '返回已创建的对象
  34.     Set Add = objNewMember
  35.     Set objNewMember = Nothing
  36.     
  37. End Function
  38. '往集合中加入一个“合作信息”对象
  39. Public Sub AddEx(obj As clsDBbase)
  40.   mCol.Add obj, "A" & obj.ID
  41.   '在加入对象是,最好同时加入其“KEY”属性
  42.   '“KEY”属性不可以是数字型,因此在前面随便加
  43.   '一个字母,此处加了一个“A”
  44. End Sub
  45. Public Property Get Item(vntIndexKey As Variant) As clsDBbase
  46. Attribute Item.VB_UserMemId = 0
  47.     '引用集合中的一个元素时使用。
  48.     'vntIndexKey 包含集合的索引或关键字,
  49.     '这是为什么要声明为 Variant 的原因
  50.     '语法:Set foo = x.Item(xyz) or Set foo = x.Item(5)
  51.   Set Item = mCol(vntIndexKey)
  52. End Property
  53. Public Property Get Count() As Long
  54.     '检索集合中的元素数时使用。语法:Debug.Print x.Count
  55.     Count = mCol.Count
  56. End Property
  57. Public Sub Remove(vntIndexKey As Variant)
  58.     '删除集合中的元素时使用。
  59.     'vntIndexKey 包含索引或关键字,这是为什么要声明为 Variant 的原因
  60.     '语法:x.Remove(xyz)
  61.     mCol.Remove vntIndexKey
  62. End Sub
  63. Public Property Get NewEnum() As IUnknown
  64. Attribute NewEnum.VB_UserMemId = -4
  65. Attribute NewEnum.VB_MemberFlags = "40"
  66.     '本属性允许用 For...Each 语法枚举该集合。
  67.     Set NewEnum = mCol.[_NewEnum]
  68. End Property
  69. Private Sub Class_Initialize()
  70.     '创建类后创建集合
  71.     Set mCol = New Collection
  72. End Sub
  73. Private Sub Class_Terminate()
  74.     '类终止后破坏集合
  75.     Set mCol = Nothing
  76. End Sub
  77. '清除集合中的全部元素
  78. Public Sub Clear()
  79.   '注意!在清除时必须倒序清除,否则要出错!
  80.   Dim i As Long
  81.   For i = mCol.Count To 1 Step -1
  82.     mCol.Remove i
  83.   Next i
  84. End Sub