Results 1 to 2 of 2

Collection of Class Modules

Threaded View

  1. #1
    Registered User
    Join Date
    07-10-2009
    Location
    San Francisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    20

    Collection of Class Modules

    Hi all.

    I am trying to create a collection of class modules. (Originally, I wanted to have a collection of user defined types. But after hours of head banging realized VBA doesn't let you do that)

    I think that the problem I am having has to do with the fact that the class i want to add to the collection has two class module's in it. [ See Below ]


    ' This is the class module that I want to add to a collection,
    ' Lets call it cMaster:
    
    Private pA As cAlpha
    Private pB As cBeta
    
    ' Gets and lets here... 
    Public Property Get A() As cAlpha
    Public Property Let A( a_ As cAlpha )
    Public Property Get B() As cBeta
    Public Property Let B( b_ As cBeta )
    Note: cAlpha and cBeta are each Class Modules that I created.


    One question, do I need to call New on cAlpha and cBeta members?

    Sub Init()
        Set pA = New cAlpha
        Set pB = New cBeta
    End Sub

    Because right now I do:

    Dim myMaster As cMaster
    Set myMaster = New cMaster
    Call myMaster.Init
    Now, I would LIKE to do the following:

    Dim Arhs As cAlpha
    Set Arhs = New cAlpha
    Arhs.val = something
    
    Dim Brhs As cBeta
    Set Brhs = New cBeta
    Brhs.val = something
    
    myMaster.A = Arhs
    myMaster.B = Brhs
    
    ' Create a collection to store all the masters
    Dim AllMasters As Collection
    Set AllMasters = New Collection
    
    
    ' BUT, ERROR EXECUTING LINE BELOW:
    
    AllMasters.Add myMaster
    The error is as follows:

    Run-time error '91':

    Object variable or With block variable not set


    BUT WHERE?


    Thanks to anyone that can help!
    Last edited by wildjester; 07-15-2009 at 12:53 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1