- Dec 23, 2003
- 3,334
- 2
- 81
I have two classes, A and B, each with a few properties and get or get/let methods for those properties. Suppose that class A has Height, Length and Width properties/class variables.
Class A also has a method aMethod which takes in a class B object as an input parameter and does not return anything. It doesn't matter the details of the method, as the problem occurs even if I have a blank method.
Because there are no constructors per se in VBA, when I create an object I establish values for its property via something like this:
Now, suppose Beta is an instance of class B. If I call
I get a "Runtime Error 438 : Object doesn't support this property or method."
If I don't set the properties of Alpha. I.e., if I just say "Set Alpha = New A," there is no error. The class method is nothing more than blank code.
Furthermore, if the method takes a non-object input, say, an Integer, it works fine regardless of whether or not I set the properties.
In summary, the below returns "Runtime Error 438"
While this runs without error:
Why does setting the properties of an object instance break this code? What is the proper way of creating object instances in VBA? How do I pass object as arguments to class methods?
Any help would be appreciated. I am writing a simple macro and I'm just getting hung up on this language.
Class A also has a method aMethod which takes in a class B object as an input parameter and does not return anything. It doesn't matter the details of the method, as the problem occurs even if I have a blank method.
Because there are no constructors per se in VBA, when I create an object I establish values for its property via something like this:
Code:
Dim Alpha As A
Set Alpha = New A
With Alpha
.Height = 1
.Length = 1
.Width = 1
End With
Now, suppose Beta is an instance of class B. If I call
Code:
Alpha.aMethod Beta
I get a "Runtime Error 438 : Object doesn't support this property or method."
If I don't set the properties of Alpha. I.e., if I just say "Set Alpha = New A," there is no error. The class method is nothing more than blank code.
Furthermore, if the method takes a non-object input, say, an Integer, it works fine regardless of whether or not I set the properties.
Code:
Public Sub aMethod ( Object As B )
End Sub
In summary, the below returns "Runtime Error 438"
Code:
Dim Alpha As A
Dim Beta As B
Set Beta = New B
Set Alpha = New A
With Alpha
.Height = 1
.Length = 1
.Width = 1
End With
Alpha.aMethod Beta
While this runs without error:
Code:
Dim Alpha As A
Dim Beta As B
Set Beta = New B
Set Alpha = New A
Alpha.aMethod Beta
Why does setting the properties of an object instance break this code? What is the proper way of creating object instances in VBA? How do I pass object as arguments to class methods?
Any help would be appreciated. I am writing a simple macro and I'm just getting hung up on this language.
Last edited: