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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,218
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,218
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,218
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,218
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,122,587
Messages
5,597,034
Members
414,116
Latest member
sfullnet

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
Top