Create new instance with variables.

papadilbert

New member
Local time
Yesterday, 20:41
Joined
Nov 29, 2011
Messages
8
Is it possible to code a VBA class that accepts variables when creating an object instance?
e.g.

Dim myClass as AClass = new AClass("aParm", "bParm")
 
(Chuckle) I remember implementing such with Object Rexx. The key to making it work in Object Rexx was knowing that the classes themselves float around in the global variable pool. So passing the string name of the class you want an instance created of to the Factory function, it then uses the Value BIF to obtain the actual object (class in this case) matching the name that was passed in. Use that to fabricate a new object, and return to the caller the new Object fresh from the Factory.
 
Dim myClass as AClass = new AClass("aParm", "bParm")
First of all, this syntax isn't valid in VBA. It's fine in .NET but not VBA ;). You can do one of:
Code:
Dim myClass as[COLOR=Blue] New [/COLOR]AClass

' Or

Dim myClass as AClass
Set myClass = New AClass
The second one is preferrable.

Is it possible to code a VBA class that accepts variables when creating an object instance?
Unfortunately you can't. The constructor class is called Initialize and to my knowledge there's no means of declaring a sub within that constructor that will allow it to take arguments.

Fyi: the destructor is Terminate.
 

Users who are viewing this thread

Back
Top Bottom