home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD1220211302000.psc / CATEGORY.CLS < prev    next >
Encoding:
Visual Basic class definition  |  2000-11-30  |  3.2 KB  |  117 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 = "Category"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = False
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = True
  14. Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
  15. Attribute VB_Ext_KEY = "Collection" ,"Item"
  16. Attribute VB_Ext_KEY = "Member0" ,"Item"
  17. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  18. 'local variable to hold collection
  19. Private mCol As Collection
  20. 'local variable(s) to hold property value(s)
  21. Private mvarCatName As String 'local copy
  22. Friend Property Let CatName(ByVal vData As String)
  23. 'used when assigning a value to the property, on the left side of an assignment.
  24. 'Syntax: X.CatName = 5
  25.     mvarCatName = vData
  26. End Property
  27.  
  28.  
  29. Public Property Get CatName() As String
  30. 'used when retrieving value of a property, on the right side of an assignment.
  31. 'Syntax: Debug.Print X.CatName
  32.     CatName = mvarCatName
  33. End Property
  34.  
  35.  
  36.  
  37.  
  38. Friend Function Add(ItemName As String, Differentiate As Boolean, Description As String, sValueKey As String, Optional sKey As String) As Item
  39.     'create a new object
  40.     Dim objNewMember As Item
  41.     Set objNewMember = New Item
  42.  
  43.  
  44.     'set the properties passed into the method
  45.     objNewMember.ItemName = ItemName
  46.     objNewMember.Differentiate = Differentiate
  47.     objNewMember.Description = Description
  48.     objNewMember.Value = 0
  49.     objNewMember.ValueKey = sValueKey
  50.     If Len(sKey) = 0 Then
  51.         mCol.Add objNewMember
  52.     Else
  53.         mCol.Add objNewMember, sKey
  54.     End If
  55.  
  56.  
  57.     'return the object created
  58.     Set Add = objNewMember
  59.     Set objNewMember = Nothing
  60.  
  61.  
  62. End Function
  63.  
  64. Public Property Get Item(vntIndexKey As Variant) As Item
  65. Attribute Item.VB_UserMemId = 0
  66.     'used when referencing an element in the collection
  67.     'vntIndexKey contains either the Index or Key to the collection,
  68.     'this is why it is declared as a Variant
  69.     'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
  70.   Set Item = mCol(vntIndexKey)
  71. End Property
  72.  
  73.  
  74.  
  75. Public Property Get Count() As Long
  76.     'used when retrieving the number of elements in the
  77.     'collection. Syntax: Debug.Print x.Count
  78.     Count = mCol.Count
  79. End Property
  80.  
  81.  
  82. Friend Sub Remove(vntIndexKey As Variant)
  83.     'used when removing an element from the collection
  84.     'vntIndexKey contains either the Index or Key, which is why
  85.     'it is declared as a Variant
  86.     'Syntax: x.Remove(xyz)
  87.  
  88.  
  89.     mCol.Remove vntIndexKey
  90. End Sub
  91.  
  92.  
  93. Public Property Get NewEnum() As IUnknown
  94. Attribute NewEnum.VB_UserMemId = -4
  95. Attribute NewEnum.VB_MemberFlags = "40"
  96.     'this property allows you to enumerate
  97.     'this collection with the For...Each syntax
  98.     Set NewEnum = mCol.[_NewEnum]
  99. End Property
  100.  
  101.  
  102. Private Sub Class_Initialize()
  103.     'creates the collection when this class is created
  104.     Set mCol = New Collection
  105. End Sub
  106.  
  107.  
  108. Private Sub Class_Terminate()
  109.     'destroys collection when this class is terminated
  110.     Set mCol = Nothing
  111. End Sub
  112.  
  113. Friend Sub Clear()
  114.   Set mCol = Nothing
  115.   Set mCol = New Collection
  116. End Sub
  117.