Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Why use Class Modules?
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). |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Why use Class Modules?
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 -- Cordially, Chip Pearson Microsoft MVP - Excel, 10 Years Pearson Software Consulting www.cpearson.com (email on the web site) "Don Wiss" wrote in message ... 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). |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Class modules: parametrize class object fields | Excel Programming | |||
Basic question - modules and class modules - what's the difference? | Excel Programming | |||
Class Modules | Excel Programming | |||
Class modules | Excel Programming | |||
Class Modules vs Modules | Excel Programming |