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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
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 Architect / Systems AnalystCommented:
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
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Dale FyeOwner, Developing Solutions LLCCommented:
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
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Not sure that fits the Class paradigm per se

But I do like the 10% increase in CA !!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 Architect / Systems AnalystCommented:
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 Architect / Systems AnalystCommented:
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 Architect / Systems AnalystCommented:
Well ... yeah, blues, classic rock and 60 Motown ... that's what I do ...
>>>  Crank It Up
0
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPDesigner and DeveloperCommented:
mx,  I did not know you were so artistic. Very cool Dude!
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
thx bro ... are you going to the Summit ?

mx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.