OOP question

Still trying to get my head around the mechanics of instantiating objects. To simplify only a little:

I have a SQLite database that contains an employee table with many different types of employees, statuses, classifications, etc.
I need to print a report that will contain summary counts of the different classifications, statuses, etc.
I created a Class that contains a property for each type of summary total I need to calculate.
I started to add a method that does the calculations - it would receive a parameter that is a recordset that is a sub-set of the employee table (or maybe the entire table)
But a method attached to a class can’t instantiate itself - correct?
Can I instantiate the summary class in another process where the recordset has been created and then call that method of the object?
If I can do this then I also want to add another method that prints the summary report.

the calculate summary method was going to put the totals in the properties of the class, but when writing the method, there is no existing object to update.

thanks in advance

“methods” are not instantiated… classes are… and a class can contain methods

Why do you believe you even need a “class”… wouldn’t a “module” with appropirate static methods work just as well?

normally you create a class object when you need multiple instances (or think you will at some point require multiple) and each instance may or may not have different attributes.

A “playing card” is a good example.
You would normally have 52 instances, and each instance has different suit and rank

I actually agree with what you said completely. I’m just trying to use “objects” as much as possible since that seems to be the “preferred” way of doing stuff. I actually think OOP is as much a pain in the …backside as it is a help.

So, I am going to abandon the class and just use a module.

thanks Dave.

You should have a look at Bob Keeney’s free ActiveRecord class. Just google for “bkeeney ActiveRecord”

If you want to give the class another shot as a learning exercise, I think that what you are looking for is a Constructor method.

Add a method to your class and call it Constructor with a parameter such as data as RecordSet, then you can instantiate the class using the RecordSet like this:

dim data as RecordSet = MyDatabaseMethodThatReturnsARecordSet dim myClassInstance as new MyClass(data)

The instance of MyClass will be created and you can put code in the Constructor method to do whatever you want with the data that is in the RecordSet.

Then you can add your Summary method to the class can call that after your instance has been created.

Jared, I like your idea. I am going to do it that way just to get the feel of doing so. thanks guys.