Results 1 to 11 of 11

Class with property as collection of another class

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-28-2007
    Location
    New York, NY
    MS-Off Ver
    2007
    Posts
    120

    Class with property as collection of another class

    I've just started to learn how to use classes, so before I explain my problem here, does anyone know of any online resources to learn more about classes in VBA? I read this already: http://www.cpearson.com/excel/Classes.aspx.


    Anyway, here's my problem. I've created a class called CStock. It has 5 standard properties (with Get/Let methods) as explained in that article above. Nothing fancy here.

    I also want to create a CPortfolio class that has 3 properties: pName, pNumberofPositions, and pHoldings. the first 2 are stardard, but the last one is different. I want it to somehow keep a collection of stocks. I tried putting:

    Private pHoldings As Collection
    Public Property Get Holdings() As Collection
        Holdings = pHoldings
    End Property
    
    Public Property Let Holdings(Value As Collection)
        pHoldings = Value
    End Property
    in the CPortfolio module. and then i tried calling:

    port.Holdings.Add stk
    port.Holdings.Add stk2
    in a regular sub, but the sub goes into the Get instead of the Let and i get "Complie Error: Argument Not Optional"


    Anyone know what I'm trying to do here? Cuz I'm not sure I even know. Also, after I get this working, I want to create a CBook class that holds a bunch of portfolios in the same manner. am i going about this the wrong way?

    Thanks,
    Joe
    Last edited by MCCCLXXXV; 11-25-2008 at 12:23 PM. Reason: spelling

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