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
 

Some videos you may like

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,061
Office Version
  1. 365
Platform
  1. Windows
Could we see the code?
 

Hap

Well-known Member
Joined
Jul 20, 2005
Messages
647
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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,061
Office Version
  1. 365
Platform
  1. Windows
And where are you getting the error?

And how have you defined/declared AreaClass?
 

Hap

Well-known Member
Joined
Jul 20, 2005
Messages
647

ADVERTISEMENT

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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,061
Office Version
  1. 365
Platform
  1. Windows
And how have you declared/defined AreaClass? ie can we see the code?

By the way why do you have () around NewArea?
 

Hap

Well-known Member
Joined
Jul 20, 2005
Messages
647

ADVERTISEMENT

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
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,061
Office Version
  1. 365
Platform
  1. Windows
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)
 

Hap

Well-known Member
Joined
Jul 20, 2005
Messages
647
That was clearly part of my problem.

changed to:

newArea = CornerSort (newArea)


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

Watch MrExcel Video

Forum statistics

Threads
1,118,812
Messages
5,574,458
Members
412,595
Latest member
slim313
Top