PDA

View Full Version : Solved: Class Modules??



ProteanBeing
10-06-2007, 02:36 PM
I've written a lot of modules but no class modules mainly because I don't know what the option is for. Can anyone give me a easy to understand explanation? Thanks.

Bob Phillips
10-06-2007, 03:04 PM
In a word, no!

Classes are a way to define custom objecst within your application. Such objects could be something as obvious as person class, or something less obvious, such as recently access document (I am writing a classes turorial using MRU :-)).

Each class/object has properties and methods, that is things that describe the object, and things that can be done to the object, or that the object can do. For instance, a person could have a Gender property (Male or Female), a weight property, a height property, etc. And a person can walk, can talk, grow, etc. Not that a method can affect a property, grow and the height is increased :-).

An MRU can have a property of length, parent app (say Word, Excel), etc. It can be opened, can be deleted, and so on.

And that is only scratching the surface of classes. I haven't (nor am I going to) touched on inheritance, encapsulation, polymorphism. There is much more to understand to understand classes.

And worst of all, if I gave you a fully working example of a class, you would probably say that all of that could be achieved without classes, and you would probably be correct.

To my mind, forgetting about the true OO aspects of classes, they are useful because they allow you to abstract one aspect of a solution from the problem, identify that you need a particular class/object, and then you can go away and design that class in isolation, build it in isolation, and test in isolation. Once you have it working in this splendid isolation, you have a clearly defined APLI (the public properties and methods), and you utilise that class from one or more of your business apps.

Bob Phillips
10-06-2007, 03:06 PM
Oh, B TW, if my explanation didn't help you, try this page from Chip Pearson

http://www.cpearson.com/Excel/Classes.aspx

ProteanBeing
10-06-2007, 03:14 PM
I have used classes in C++ programming and I understand OOP. I was simply trying to understand how to it works in VBA.

BTW - what is MRU (it sounds familiar)

Bob Phillips
10-06-2007, 03:21 PM
If you have used classes in C++, then I don't understand your question. It works in VBA same as it it works in VB, same as it works in C++. You might implement it differently because of language differences, but it works the same.

MRU - Most Recently Used.

ProteanBeing
10-06-2007, 03:29 PM
I believe I'm hung up on the syntax. Basically if I have functions and variables in a class called class1, then I Dim it:

Dim v as class1

Then I can manipulate it like this:

v.function(parameters)
v.publicvariable = 23

Bob Phillips
10-06-2007, 03:40 PM
Yes, that is right, so what is the problem?

And that is nothing like the question that you originally asked.

ProteanBeing
10-06-2007, 03:44 PM
Sorry. I should have been more clear. Thanks for your help