Consulting

Results 1 to 8 of 8

Thread: Solved: Class Modules??

  1. #1
    VBAX Tutor
    Joined
    Oct 2007
    Posts
    210
    Location

    Solved: Class Modules??

    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.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Oh, B TW, if my explanation didn't help you, try this page from Chip Pearson

    http://www.cpearson.com/Excel/Classes.aspx
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  4. #4
    VBAX Tutor
    Joined
    Oct 2007
    Posts
    210
    Location
    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)

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Tutor
    Joined
    Oct 2007
    Posts
    210
    Location
    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

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Yes, that is right, so what is the problem?

    And that is nothing like the question that you originally asked.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Tutor
    Joined
    Oct 2007
    Posts
    210
    Location

    Solved: Class Modules??

    Sorry. I should have been more clear. Thanks for your help

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •