A Link Class


The CLink class looks like this:

‘ CLink class
Public Item As Variant ‘ Default member
Public NextLink As CLink

This is that rarest of beasts—a no-code class. The data is stored in Item. Because Item is a Variant, different links can contain different kinds of data. Other languages use untyped pointers to hold any kind of data, but the Variant solution is more convenient. You could, of course, make Item a specific type if you wanted a linked list of Strings or Doubles. Such a class would be more efficient, but less flexible. Visual Basic uses the Variant strategy—there’s only one Collection class, no LongCollection or StringCollection.


Item is the default property, so you can actually use the object name to refer to the Item property. Get used to it. In this book, any property or method named Item is likely to be the default. The Collection class sets a standard, and I’m following it. Incidentally, when you look at the CLink class, it’s easy to think of Item and NextLink as fields of a UDT. Don’t be deceived. They are properties, and you’ll get a procedure call every time you use one.


The NextLink property has the same type (CLink) as the current link. This link might contain another link, which might contain another link, and so on. Actually, it’s more accurate to think of the first object as pointing to the second object. The objects in the list are separate and independent of each other. Internal pointers give them the illusion of containing other objects.