Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Constructors for Classes

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Constructors for Classes

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
--
HTH...

Jim Thomlinson


"Gary F" wrote:

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!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Constructors for Classes

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" wrote:

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
--
HTH...

Jim Thomlinson


"Gary F" wrote:

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!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Constructors for Classes

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" wrote:

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" wrote:

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
--
HTH...

Jim Thomlinson


"Gary F" wrote:

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!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Classes alish Excel Discussion (Misc queries) 3 October 30th 07 01:03 PM
Classes containing Classes Adam[_15_] Excel Programming 2 April 1st 06 07:47 AM
VBA and Constructors; exist? McManCSU[_16_] Excel Programming 3 August 8th 05 03:18 PM
Using Classes in .xla oli Excel Programming 2 June 3rd 05 11:37 AM
Using classes defined in an add-in Lieven Mettepenningen[_2_] Excel Programming 1 January 8th 04 03:01 PM


All times are GMT +1. The time now is 02:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"