A template for building collection class modules

A template for building collection class modules

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 TEMPLATECLASSES subdirectory under the main VB6 directory:

VERSION 1.0 CLASSBEGIN  MultiUse = -1  'True  Persistable = 0  'NotPersistable  DataBindingBehavior = 0  'vbNone  DataSourceBehavior  = 0  'vbNone  MTSTransactionMode  = 0  'NotAnMTSObjectENDAttribute VB_Name = "CollectionClassName"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = TrueAttribute VB_PredeclaredId = FalseAttribute VB_Exposed = False'----------------------------------------------------' A template for Collection Classes'----------------------------------------------------'' What to do after you add this template to the' current program:'' 1) change the name of the class as needed' 2) use the search and replace command to change all'    instances of "BaseClassName" (without quotes), into'    the actual name of the base class' 3) optionally modify the ADD method to initialize'    properties of the NEWITEM object before adding it'    to the private collection' 4) delete these remarks'------------------------------------------------------Option Explicit' The private collection used to hold the real dataPrivate m_PrivateCollection As CollectionPrivate Sub Class_Initialize()    ' explicit assignment is slightly faster than auto-instancing    Set m_PrivateCollection = New CollectionEnd Sub' Add a new BaseClassName item to the collectionPublic Sub Add(newItem As BaseClassName, Optional Key As Variant)Attribute Add.VB_Description = "Adds a member to a Collection object"    ' TO DO: initialize new item's properties here    ' ...    ' add to the private collection    m_PrivateCollection.Add newItem, KeyEnd Sub' Remove an item from the collectionPublic Sub Remove(index As Variant)Attribute Remove.VB_Description = "Removes a member from a Collection object"    m_PrivateCollection.Remove indexEnd Sub' Return a BaseClassName item from the collectionFunction Item(index As Variant) As BaseClassNameAttribute 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' Return the number of items in the collectionProperty Get Count() As LongAttribute Count.VB_Description = "Returns the number of members in a collection"    Count = m_PrivateCollection.CountEnd Property' Remove all items from the collectionPublic Sub Clear()Attribute Clear.VB_Description = "Removes all members from a Collection object"    Set m_PrivateCollection = New CollectionEnd Sub' Implement support for enumeration (For Each)Function NewEnum() As IUnknownAttribute NewEnum.VB_UserMemId = -4Attribute NewEnum.VB_MemberFlags = "40"    ' delegate to the private collection    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:

  Persistable = 0  'NotPersistable  DataBindingBehavior = 0  'vbNone  DataSourceBehavior  = 0  'vbNone  MTSTransactionMode  = 0  'NotAnMTSObject

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as