|
|
|
The following is a template for building collection class modules in a very quick and effective way. Copy-and-paste this code into Notepad, that save it to a file named "COLLECTION CLASS.CLS" in the \TEMPLATE\CLASSES subdirectory under the main VB6 directory: |
Click here to copy the following block | VERSION 1.0 CLASS BEGIN MultiUse = -1 Persistable = 0 DataBindingBehavior = 0 DataSourceBehavior = 0 MTSTransactionMode = 0 END Attribute VB_Name = "CollectionClassName" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = False
Option Explicit
Private m_PrivateCollection As Collection
Private Sub Class_Initialize() Set m_PrivateCollection = New Collection End Sub
Public Sub Add(newItem As BaseClassName, Optional Key As Variant) Attribute Add.VB_Description = "Adds a member to a Collection object" m_PrivateCollection.Add newItem, Key End Sub
Public Sub Remove(index As Variant) Attribute Remove.VB_Description = "Removes a member from a Collection object" m_PrivateCollection.Remove index End Sub
Function Item(index As Variant) As BaseClassName Attribute Item.VB_Description = "Returns a specific member of a Collection " _ & "object either by position or key" Attribute Item.VB_UserMemId = 0 Set Item = m_PrivateCollection.Item(index) End Function
Property Get Count() As Long Attribute Count.VB_Description = "Returns the number of members in a collection" Count = m_PrivateCollection.Count End Property
Public Sub Clear() Attribute Clear.VB_Description = "Removes all members from a Collection object" Set m_PrivateCollection = New Collection End Sub
Function NewEnum() As IUnknown Attribute NewEnum.VB_UserMemId = -4 Attribute NewEnum.VB_MemberFlags = "40" Set NewEnum = m_PrivateCollection.[_NewEnum] End Function |
You can now add a new collection class by selecting the "Collection Class" template when you add a class module to your current project. If you don't see the list of templates, enforce this capability in the Environment tab of the Tools | Options dialog box. After you've added the template to the project, follow the easy 4-step procedure described at the top of the file to turn it into a real collection class. Note that the template above works only under VB6. To have it work under VB5, you must delete the following four lines, near the beginning of the file: |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|