home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD58155152000.psc / CMyItemDatas.cls < prev    next >
Encoding:
Visual Basic class definition  |  2000-05-09  |  2.6 KB  |  92 lines

  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 = "CMyItemDatas"
  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" ,"CMyItemData"
  16. Attribute VB_Ext_KEY = "Member0" ,"CMyItemData"
  17. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  18. 'local variable to hold collection
  19. Private mCol As Collection
  20.  
  21. Public Function Add(Optional sMenuText As String, Optional fType As Long, Optional iButton As Integer, Optional sKey As String) As CMyItemData
  22.     'create a new object
  23.     Dim objNewMember As CMyItemData
  24.     Set objNewMember = New CMyItemData
  25.  
  26.  
  27.     'set the properties passed into the method
  28.     objNewMember.sMenuText = sMenuText
  29.     objNewMember.fType = fType
  30.     objNewMember.iButton = iButton
  31.     If Len(sKey) = 0 Then
  32.         mCol.Add objNewMember
  33.     Else
  34.         mCol.Add objNewMember, sKey
  35.     End If
  36.  
  37.     'return the object created
  38.     Set Add = objNewMember
  39.     Set objNewMember = Nothing
  40.  
  41. End Function
  42.  
  43. Public Property Get Item(vntIndexKey As Variant) As CMyItemData
  44. Attribute Item.VB_UserMemId = 0
  45.     'used when referencing an element in the collection
  46.     'vntIndexKey contains either the Index or Key to the collection,
  47.     'this is why it is declared as a Variant
  48.     'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
  49.   Set Item = mCol(vntIndexKey)
  50. End Property
  51.  
  52.  
  53.  
  54. Public Property Get Count() As Long
  55.     'used when retrieving the number of elements in the
  56.     'collection. Syntax: Debug.Print x.Count
  57.     Count = mCol.Count
  58. End Property
  59.  
  60.  
  61. Public Sub Remove(vntIndexKey As Variant)
  62.     'used when removing an element from the collection
  63.     'vntIndexKey contains either the Index or Key, which is why
  64.     'it is declared as a Variant
  65.     'Syntax: x.Remove(xyz)
  66.  
  67.  
  68.     mCol.Remove vntIndexKey
  69. End Sub
  70.  
  71.  
  72. Public Property Get NewEnum() As IUnknown
  73. Attribute NewEnum.VB_UserMemId = -4
  74. Attribute NewEnum.VB_MemberFlags = "40"
  75.     'this property allows you to enumerate
  76.     'this collection with the For...Each syntax
  77.     Set NewEnum = mCol.[_NewEnum]
  78. End Property
  79.  
  80.  
  81. Private Sub Class_Initialize()
  82.     'creates the collection when this class is created
  83.     Set mCol = New Collection
  84. End Sub
  85.  
  86.  
  87. Private Sub Class_Terminate()
  88.     'destroys collection when this class is terminated
  89.     Set mCol = Nothing
  90. End Sub
  91.  
  92.