Constructors for Classes

G

Gary F

Every so often I want to create a class in VBA, but VBA doesn't seem to have
the concept of a constructor for the class - so you have to (1) call NEW, (2)
makes sure that the caller sets up the object right.

I'm sure there's an approach for simulating the above (a pattern). Can
someone share it?

Thanks!
 
G

Gary F

I wonder if I could do something like make the classes variables private,
then make a public method in a module called "New[Name of Class]" that
creates the class...hmm...
 
J

Jim Thomlinson

Here is a tid bit on declaring varaibles and instantiating objects and such

http://www.cpearson.com/excel/variables.htm

Take a look at the section "Don't Use The New Keyword In A Dim Statement"
for a little bit of insight into objects...

--
HTH...

Jim Thomlinson


Gary F said:
I wonder if I could do something like make the classes variables private,
then make a public method in a module called "New[Name of Class]" that
creates the class...hmm...

Jim Thomlinson said:
There is class initailize which is as close as you will get to a consturctor.
Chip Pearson has a good discussion on instantiating classes...

http://www.cpearson.com/excel/ClassModules.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top