+ Reply to Thread
Results 1 to 3 of 3

Splitting code for a Class across multiple modules?

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    Houston TX
    MS-Off Ver
    Excel 2007
    Posts
    19

    Splitting code for a Class across multiple modules?

    I have written code for Choicer, which is a Class Module. Broadly, the Choicer does two big things: it constructs a bunch of tables, and it puts Validation drop-down menus into cells. There's a lot of code in the module; it's getting hard for me to navigate. I'd like to split the module into two modules.

    For a regular module, this would be no problem. For a class module, how do I do it? I don't want to create two different classes; I want to spread the code for a single class across two files.

    If VBA had inheritance, I'd code two separate classes and let Choicer inherit both of them. Is there a comparable approach in VBA?

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,431

    Re: Splitting code for a Class across multiple modules?

    I think the best you can do is create objects within the parent class referencing the 2 class modules for tables and menus.


    Holding class, Class1
    Please Login or Register  to view this content.
    Menu class, Class2
    Please Login or Register  to view this content.
    Table class, Class3
    Please Login or Register  to view this content.


    Module
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    12-18-2012
    Location
    Houston TX
    MS-Off Ver
    Excel 2007
    Posts
    19

    Re: Splitting code for a Class across multiple modules?

    Andy, thanks. But Choicer holds a large number of parameters, and both the menu construction and the table construction use these parameters a lot. If I split the code as you suggest, then I have to pass the Choicer instance as an Arg to each method, and then code like
    Please Login or Register  to view this content.
    gets real cluttered with
    Please Login or Register  to view this content.
    which is what I was trying to avoid. So that means a lot of refactoring and then putting up with uglified code.

    I appreciate you letting me know that what I want to do isn't worth the trouble in VBA.

+ Reply to Thread

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