Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class Modules - Friend or Foe?

Status
Not open for further replies.

MattSmithProg

Programmer
Sep 9, 2001
76
0
0
AU
Hi,

I have been programming in VBA for over 2 years now and have never found the need to use class modules. For all the reading I do everyone is recomending using them. I can see the benefits of using them but what I would use them for I can put in normal modules.

The major reason that I would use them for is common code that I use in many of my apps. If the code could be referenced in one place such that I only have to make any modifications in one place and all references to the class modules reflect the changes would be ideal. However, I am stumped as to how to do this. I thought adding a reference to the workbook that contains the class module would be the solution. However, it doesn't seem to work.

Does anyone have any ideas.

Thanks Matt Smith

No two nulls are the same
 
Hiya,

well, why use class modules? That's a tough question because you can get along without them quite happily. However, they do make life easier. Take our tools, for instance. We have to refer to several types of data, all stored in a Sybase database. What we've done is to create classes for each data type that'll allow us to:
- connect to Sybase
- get the data we need
- use it in xl reports we create

The big advantage is re-use: we store updated versions of all classes we've created in sourcesafe; when a class is updated, we redistribute the class amongst all tools.
If we need to create a new tool, we start by inclusding our Sybase class modules - this way, the only thing left to program is the creation of the new report type ...
Another advantage = you don't have to expose all your code in a proc; the code that retrieves our data is neatly tucked away in the class & we only need to call the actual class method (which is nothing more than a public sub or function in your class) to run the code.

Try googling "class modules" & you'll get loads of info; here's some MS sites that are useful (well, marginally useful - they're full of "ain't we greats" ;-) but if you read doggedly on you can get some nfo out of them)


Just my 2pee - for what they're worth ... ;-)

Cheers
Nikki
 
Thanks Nikki,

I was hoping that there may be any easy way to redistribute the class modules when a change has been made. Maybe not?

Oh well

I will probably when I get a chance, (Our organisation is moving from Win 95, Office 97 to Win XP ,Office XP), start recoding some of my more commonly used functions to Class Modules.

Thanks for the friendly advice Matt Smith

No two nulls are the same
 
I'm not sure what you're buying yourself by bunching several unrelated or loosely related procedures into a class module. You may as well put them together in a regular code module - in either case you'll need to export the module and import into other projects. But maybe I just don't understand the true spirit of OOP (hey, I'm linear! ;-) )
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top