Home
Link To Us
Components
Resources










Site Menu

An Overview in Creating an ActiveX DLL for Use with ASP Scripts

Available ActiveX Components for Download

Search the Web for other ASP Tutorials

A Note From the Author

A Good Object Reference
cover
More Resources











An Overview in Building Collections In ASP and Visual Basic Type ActiveX COM Objects
By Derrald Farnsworth-Livingston

Introduction

A collection represents a group of items that has predefined methods and properties, we will discuss this in more detail later. We will focus on collections as they are used to hold objects.

Let's Get Started

Lets create an object to use. For instance, perhaps we want to have a candy bar. Our candy bar will have various properties associated with it, nuts, chocolate, coconut, etc. To create our candy bar object we should create a new class in our Visual Basic DLL. We will call this clsCandyBar. It will have three properties, the first will be the name of the candy bar, the next will be the main kind of candy bar (chocolate, sugar, etc.) the second being a filling (caramel, coconut, etc.)

Option Explicit
Public Name As String
Public MainType As String
Public Filling As String

That will be our basic definition for now. We can add more properties and methods to this class later.

Now that we have a candy bar we need a way to distribute these candy bars in order to turn a profit. There is no better way then with a vending machine. Because a vending machine holds a multitude of candy bars and different ones to boot we need a way to contain multiple objects. We can accomplish this task by using collections.

Like I said before, a collection represents a group of items that has predefined methods and properties. This includes the Count property, the Item method, and the Add method, and the Remove Method. Two values are associated with each object in a collection. The position of the object is the first value and the key is the optional second value. The key value is a string that is used to uniquely identify the object.

Overview of the properties and methods associated with a collection object:

Count Property:Allows you to obtain the number of items in the collection.
Item Method:Returns the value of the variant of the item selected. An item can be selected by passing it the position or the key string value.
Add Method:This method has four arguments associated with it: item, key, before, after. The first argument, item is required. The before and after arguments can contain either a string that references the position or the key of an existing item. This adds the current item before or after the item specified depending on which parameter you select. Only one can be used at a time.
Remove Method:Removes an item from the collection by referencing either the string key value or the position.

Using Collections

A collection has a number of advantages that makes it ideal for many situations. For instance, a collection can handle any data type, the keys are user-defined strings making it easier to reference, a large amount of data can be stored and transferred using collections. However, because of their robust nature the memory requirements of collections are fairly high and may not be necessary in certain cases.

Creating a collection

Let’s say we have a vending machine and in this vending machine are various candy bars. We could create the vending machine as the collection of the candy bar object. We will go ahead and “build” the vending machine.

Dim VendingMachine As New Collection
Next

Sections

Section 1: Beginning Collections
Section 2: Creating a Collection

The Bookworm
Search the Tutorial-Web library for books on any topic!

Sponsors

Search Now:
In Association with Amazon.com

Counter