Why use classes in VBA?

This is mroe of a why question as opposed to a how question.  I have been looking at classes and trying to understand the benefits.  I really don't see any so if anyone has examples or explanations of why they are considered good programming usage, would appreciate.

Sandra
Sandra SmithRetiredAsked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
Not sure that fits the Class paradigm per se

But I do like the 10% increase in CA !!
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Imagine you had an application wherein you need to start/pause/stop multiple timers.  I have a Class Module that will handle this.  One Class Module will handle N instances of the timer.  

If you had to do this w/o a class module, it would be non-trival ... probably the same timer function repeated multiple times.  Not so with a Class Module ... you can instantiate as many instances as you need.

And you may not know this, but a Form/Report module is ... a Class Module :-)

mx
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Further, should it be necessary, you can expose ONLY the necessary Properties and/or Methods in the class to the 'outside' world (aka, other developers, etc).  And again, using the timer class example ... what if you needed to modify the code.  Class module - on place, self contained.  But if you had multiple timer Functions, then multiple changes ....

mx
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Another example ... I have a Class that handle Multi-Select list boxes, reading/writing selections to temp tables, etc.  This way I can (and do) have several MSLB's on one form, all operating on a separate instance of the Class.  Otherwise, a LOT more code, or more complex code would be required.

mx
0
 
Dale FyeCommented:
Joe,

Would like to see that MSLB class, if you feel like sharing.   ;-)

Dale
0
 
Sandra SmithRetiredAuthor Commented:
MX, I think I am just dense.  So, if I have employees that I need to loop through, names, ID's, job title, hire date and salary, how would making an employee class be better than using a recordset and looping through each record in the set to, say, increase salary by 10% for each employee in California?  Or would this even be a candidate for a class?

Sandra
0
 
Sandra SmithRetiredAuthor Commented:
LOL!  Wishful thinking on my part!  

So, perhaps part of my issue is not understanding when to use them.  But you have given some good information, I need to keep investigating and experimenting.  Thank you.

Sandra
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
You might want to check this out:

Introduction To Classes in VBA
http://www.cpearson.com/excel/Classes.aspx

So, you are where in CA ?

OH ... Bay Area .. 94xxx ...

mx
0
 
Sandra SmithRetiredAuthor Commented:
Yep, SF is the stomping grounds, downtown to be exact.  All those banks, trading companies, mortage brokers.......  

Thanks for the link and will definitely check it out.

Sandra
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Yeah ... prime area for hackers ... $$$$$$ $$$$$$ $$$$$

My plan WAS ... to git up to the Bay Area before the end of 2011.  OOPS ... too damn busy down here. Have 3-4 friends up that way I have not seen in many years ... Palo Alto area. Plus, the best blues guitar player on the planet ... Chris Cain, lives circa San Jose, and does not get down here often enough.

mx
0
 
Sandra SmithRetiredAuthor Commented:
Blues?? Sorry, I am old rocker from way back.  Cher, Beatles, etc anything from the 60/70's and I am in music heaven.  Ok, so now I am singing "Halfbreed" for the rest of the day!  LOL!

Sandra
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Well ... yeah, blues, classic rock and 60 Motown ... that's what I do ...
>>>  Crank It Up
0
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
mx,  I did not know you were so artistic. Very cool Dude!
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
thx bro ... are you going to the Summit ?

mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.