Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Why use Class Modules?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Don Wiss - 28 Nov 2007 12:50 GMT
I've written a large pricing application in Excel. Lots of VBA and User
Forms, but very concisely written. I need to add a feature written by
someone else. This other programmer is not known for concise code. My
question here is why has he used Class Modules instead of simply having all
the code in a regular Module.

Don <www.donwiss.com> (e-mail link at home page bottom).
Chip Pearson - 28 Nov 2007 13:32 GMT
A class module is used to encapsulate a variety of data about a particular
entity into a single entity. For example, imagine you are writing an
application that does something with employees. You could create a class
called CEmployee that would have data items for name, address, phone, etc. A
class can also contain methods (Subs and Functions), so your CEmployee class
might have a method that prints the employee's paycheck. In your
application, you would create a new instance variable of the CEmployee class
for each employee you are dealing with.  By using a class to represent one
employee, you can use a single variable to represent all the various
attributes of an employee.  In a large and complicated application, it is
MUCH easier to deal with one variable, a variable of type CEmployee, that
wraps up all the information than it is to deal with many separate,
unrelated variables. Without classes, you'd probably end up with a number of
arrays that would have to be kept in sync with one another, a task that can
quickly get quite complicated.

> This other programmer is not known for concise code.

My experience over the years has been that using classes doesn't have a
profound effect on the number of lines of code in a project. In the big
picture, classes neither increase nor decrease the number of lines of code
in a project (but using lines of code as a measure of anything is rather
inane). Classes can have a very positive effect by simplifying and
streamlining the logic of the application.

For a much more in depth look at classes with example, see
www.cpearson.com/Excel/Classes.aspx

Signature

Cordially,
Chip Pearson
Microsoft MVP  - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

> I've written a large pricing application in Excel. Lots of VBA and User
> Forms, but very concisely written. I need to add a feature written by
[quoted text clipped - 4 lines]
>
> Don <www.donwiss.com> (e-mail link at home page bottom).
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.