[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


programming with classes

Posted on 2005-04-13
Medium Priority
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

Accepted Solution

Marv-in earned 300 total points
ID: 13775463
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?

Assisted Solution

List244 earned 100 total points
ID: 13775478
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

AzraSound earned 100 total points
ID: 13775954
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

872 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