Re: Avoiding duplication in objects with large commonality

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jamie Collins (jamiecollins_at_xsmail.com)
Date: 11/19/04


Date: 19 Nov 2004 02:06:44 -0800

hooksie2@hotmail.com (Andrew) wrote ...

> I am implementing an object structure which consists of a number of
> objects and each of those objects should be accessed via a collection
> class.
>
> I'm not sure whether I can do
> anything with the "Implements" keyword but it looks like this is more
> for creating a common interface rather than common base code.

VBA supports polymorphism via Implements whereas you are looking for
more traditional inheritance which VBA does not support. I have a
standard collection class 'template' from which I change the class
name each time. And, because I have the usual default member and
NewEnum frigs, I have to do this in a text editor else risk losing
them.

In case that last comment made no sense you can 'neaten' your syntax
to

Joints("JointName").JointProperties
Pipes("PipeName").PipeProperties
etc

by making Item the default member of the class. Because this Attribute
property is invisible in VBA, you have to export the class module to a
file, open it in a text editor (e.g. Notepad) and add the magic line:

Public Property Get Item(ByVal Index As Variant) As CColumn
Attribute Item.VB_UserMemId = 0 ' <<<<< magic line
Set Item = m_colColumns.Item(Index)
End Property

(note must be Public - not Friend - and the keyword 'Item' in the
magic line must match the procedure name). While in the text editor,
you may as well add the following, which contains *two* magic lines:

Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
Set NewEnum = m_colColumns.[_NewEnum]
End Property

The above allows a For Each loop to be performed on the collection
class. Save in the text editor and re-import the class to the VBA
project.

Jamie.

--


Relevant Pages

  • Re: Sorting within a form
    ... The expression builder attempt put both statements in the on click ... VBA code editor. ... VBA editor, ... button to sort on. ...
    (microsoft.public.access.forms)
  • Re: Mac Word add-in - where to start
    ... get the Word AppleScript Reference from the MacTopia website ... Similar to where John is sending you in VB Editor (where you can ... > 1) Start the Microsoft Word VBA Editor ... > Any book you get on PC VBA is fine in Mac Word. ...
    (microsoft.public.mac.office.word)
  • Re: Avoiding duplication in objects with large commonality
    ... Maybe it is only an issue if you change the actual collection class ... > more traditional inheritance which VBA does not support. ... open it in a text editor and add the magic line: ... > Public Property Get ItemAs CColumn ...
    (microsoft.public.excel.programming)
  • Re: Can one insert a variable/cell ref. in the heading
    ... I have no problems getting the code in the editor, ... I use a downloaded version of excel 2003.I think thou I understand ... "Dave Peterson" wrote: ... >> litle Pascal and I have tried some VBA as well. ...
    (microsoft.public.excel.misc)