Class and Function Q

Hap

Well-known Member
Joined
Jul 20, 2005
Messages
647
Is it possible to send a class object to a function? I keep getting an error 438 "Object doesn't support this property or method".

Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
This is the function call:

CornerSort (newArea)

This is the function:
Public Function CornerSort(UnSorted As AreaClass) As AreaClass

Dim firstPt As PolyPoint
Dim xMx As Double
Dim xMn As Double
Dim iitem As PolyPoint


xMx = UnSorted.theCollection(1).X
xMn = UnSorted.theCollection(1).X

For Each iitem In UnSorted.theCollection
If iitem.X > xMx Then
xMx = iitem.X
End If
If iitem.X < xMn Then
xMn = iitem.X
End If
Next iitem
For Each iitem In UnSorted.theCollection
iitem.X = iitem.X - 0.5 * (xMx + xMn)
Next iitem

CornerSort = UnSorted

End Function
 
Upvote 0
And where are you getting the error?

And how have you defined/declared AreaClass?
 
Upvote 0
I have defined AreaClass in a class module. "newArea" is a instance of the class that I have used to do other things in the code so I know it is a valid variable. I am getting the error in the line when I call the function.
 
Upvote 0
And how have you declared/defined AreaClass? ie can we see the code?

By the way why do you have () around NewArea?
 
Upvote 0
How else should the function call look?

This is the area class:

Private ashape As String
Private areaKey As String
Private quantiI As Long
Private quantiM As Long
Public theCollection As Collection
Property Get Key() As String
Key = areaKey
End Property
Property Let Key(sKey As String)
areaKey = sKey
End Property
Property Get shape() As String
shape = ashape
End Property
Property Let shape(uShape As String)
ashape = uShape
End Property
Property Get QuantityIdentical() As Long
QuantityIdentical = quantiI
End Property
Property Let QuantityIdentical(uQuant As Long)
quantiI = uQuant
End Property
Property Get QuantityMirror() As Long
QuantityMirror = quantiM
End Property
Property Let QuantityMirror(uQuantM As Long)
quantiM = uQuantM
End Property

Private Sub Class_Initialize()
Set theCollection = New Collection
End Sub
 
Upvote 0
As far as I know the function call should only have brackets around the arguments if it is on the right of a assignment.

eg
Code:
x = CornerSort (newArea)
 
Upvote 0
That was clearly part of my problem.

changed to:

newArea = CornerSort (newArea)


now I am getting a different error in the function itself.
 
Upvote 0

Forum statistics

Threads
1,213,581
Messages
6,114,438
Members
448,573
Latest member
BEDE

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top