programming with classes

Posted on 2005-04-13
Last Modified: 2013-11-23
Hi All,
             just started learning classes hoping to add some organization to my code. Bit of learning but I get a gut feeling that I missing out big time doing without them.
            I have a question of the following kind. I have two modules in a project - a module and a class module. Now what would be the right code structure strategy.

  1. I mean, my main code goes to the just module and all property, methods,and events subs and procedures go to the class module associated with the class object at hand, right?  
  2. What if a method procedure gets big and I see that some sub procedures or functions are in order. Where do I put those, the same class module? the main code module? another module. If they stick in the class module wouldn't they become that class methods? Confusing.

Question by:Autofreak
    LVL 6

    Accepted Solution

    here is the way i look at it:

    form code holds any functions / variables just for that form

    if many forms use a function or variable i put it in a module where i have public shared stuff

    a class i consider an object that will encapsulate a bunch of functions and properties like a person class whould hold name address variables / properties and then maybe have functions to format data or somthing.

    if you procedure gets big you can have it either place - the main called function procedure will be decalred as public and the support functions can be decalred as private.

    a class can access functions in your modules if they are in the same project.

    if you get confused draw a picture - draw a big circle and put variables and functions in it that pertain to the name of the object - other stuff goes outside of it.

    the circle becomes your class.

    that was a bit of rambling - i hope i didnt confuse you more. did that help more questions?
    LVL 8

    Assisted Solution

    AutoFreak, normally uncommon functions will go in your form. That being functions that will
    not be very helpful to future projects, or other forms in the current project.

    Then, in your .Bas module, you would put functions that are either public to ALL of your forms,
    or that could be useful in other projects later on.

    The .Cls module, then you would use more for creating objects, much like active X controls,
    yet without all the visual.
    LVL 28

    Assisted Solution

    To the best of your ability, make classes as standalone as possible.  They should be able to exist on their own.  They shouldn't rely on a function in a regular module, or some API declaration elsewhere.  Define the class and the object it will represent, and anything that class requires should be put into the class itself.  Certain functions that are simply "helpers" but not relevant to an outsider using the class should be declared Private.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now