+ Reply to Thread
Results 1 to 7 of 7

many subs or many modules

  1. #1
    Registered User
    Join Date
    07-25-2006
    Posts
    11

    Red face many subs or many modules

    Is it best to program many subs and functions into one module or one sub per module resulting many modules? What are the pro and cons using, or efficiency in either of these methods.
    Thanks,

  2. #2
    Die_Another_Day
    Guest

    Re: many subs or many modules

    While I have not had any classes in programming, I keep one module,
    mdlFunctions, with the functions that I will use frequently, then one
    other, mdlMain, module with the main program. If I have more that one
    program in a project I create a separate module for each program. My
    mdlFunctions is easily available to both routines and when I later go
    back to look for those functions it's easier to find them than if I had
    to search through all the "Main" modules. Another advantage of my
    mdlFunctions is that on starting a new project, I can simply import
    mdlFunctions and have a good start for what I usually need to do.

    Charles
    xl Geek
    webby2006 wrote:
    > Is it best to program many subs and functions into one module or one sub
    > per module resulting many modules? What are the pro and cons using, or
    > efficiency in either of these methods.
    > Thanks,
    >
    >
    > --
    > webby2006
    > ------------------------------------------------------------------------
    > webby2006's Profile: http://www.excelforum.com/member.php...o&userid=36744
    > View this thread: http://www.excelforum.com/showthread...hreadid=567498



  3. #3
    Jim Thomlinson
    Guest

    RE: many subs or many modules

    There are no hard and fast rules here but the idea is to try to keep things
    organized as best you can. Sometimes these things get to be very large and it
    is not efficient to have everything in one module any more that it is
    efficient to have many, many modules. The best practice is to organize
    similar subs and functions together into modules that you have named. For
    instance I will often have a module called modProtection where I keep all of
    my protection and security procedures. I will have another module called
    modFormatting where I keep all of my procedures that deal with reformatting
    sheets. By grouping similar functionallity together it makes the program
    easier to debug. When something goes wrong I know where to look.
    --
    HTH...

    Jim Thomlinson


    "webby2006" wrote:

    >
    > Is it best to program many subs and functions into one module or one sub
    > per module resulting many modules? What are the pro and cons using, or
    > efficiency in either of these methods.
    > Thanks,
    >
    >
    > --
    > webby2006
    > ------------------------------------------------------------------------
    > webby2006's Profile: http://www.excelforum.com/member.php...o&userid=36744
    > View this thread: http://www.excelforum.com/showthread...hreadid=567498
    >
    >


  4. #4
    Jim Thomlinson
    Guest

    RE: many subs or many modules

    There are no hard and fast rules here but the idea is to try to keep things
    organized as best you can. Sometimes these things get to be very large and it
    is not efficient to have everything in one module any more that it is
    efficient to have many, many modules. The best practice is to organize
    similar subs and functions together into modules that you have named. For
    instance I will often have a module called modProtection where I keep all of
    my protection and security procedures. I will have another module called
    modFormatting where I keep all of my procedures that deal with reformatting
    sheets. By grouping similar functionallity together it makes the program
    easier to debug. When something goes wrong I know where to look.
    --
    HTH...

    Jim Thomlinson


    "webby2006" wrote:

    >
    > Is it best to program many subs and functions into one module or one sub
    > per module resulting many modules? What are the pro and cons using, or
    > efficiency in either of these methods.
    > Thanks,
    >
    >
    > --
    > webby2006
    > ------------------------------------------------------------------------
    > webby2006's Profile: http://www.excelforum.com/member.php...o&userid=36744
    > View this thread: http://www.excelforum.com/showthread...hreadid=567498
    >
    >


  5. #5
    Jeff
    Guest

    RE: many subs or many modules

    Although I am not a professional programmer I have been using VBA in Excel
    for years. I originally put one or two subs in a module. Sounded good at
    the time but when I later went back to edit a sub I had a difficult time
    remembering what module it was in. I currently have all my subs that are
    related to a particular spreadsheet in one modules. Editing is much simpler
    now because I can go up to the drop down box that lists all of my
    subroutines, select the one I want to work on and it takes me right to it.

    I agree with the others that have indicated orgination is the key. So it
    basically boils down to whatever works best for you. For me one module with
    many subs fits best in daily practices. If I get to the point where I have a
    multitude of subs in a single module, I will probably do as someone else
    stated and separate subs with like functions into various modules. Haven't
    reached that point yet!

    Jeff Boyle
    Isothermal Community College
    [email protected]

    "webby2006" wrote:

    >
    > Is it best to program many subs and functions into one module or one sub
    > per module resulting many modules? What are the pro and cons using, or
    > efficiency in either of these methods.
    > Thanks,
    >
    >
    > --
    > webby2006
    > ------------------------------------------------------------------------
    > webby2006's Profile: http://www.excelforum.com/member.php...o&userid=36744
    > View this thread: http://www.excelforum.com/showthread...hreadid=567498
    >
    >


  6. #6
    witek
    Guest

    Re: many subs or many modules

    webby2006 wrote:
    > Is it best to program many subs and functions into one module or one sub
    > per module resulting many modules? What are the pro and cons using, or
    > efficiency in either of these methods.
    > Thanks,
    >
    >

    Keep functions somehow connect to each other in one module.
    Create as many modules as you need to keep structure of entire project
    clear.

    Read this
    http://www.answers.com/topic/cohesion-computer-science


  7. #7
    Registered User
    Join Date
    07-25-2006
    Posts
    11

    Thumbs up

    Thank you for all your replies.

    I am glad I have not strayed too far from logically grouping similar routines into the one module like Jim has mentioned. i.e. all formatting in one module and files manipulation in another.

    Many many thanks.

+ 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