returning an object from a collection...'#VALUE!' error

MikeAshton55Mad

New Member
Joined
Nov 4, 2004
Messages
49
Hello help desk! :)

I have learned so much on this board it's amazing. Of course, it's kept me reaching for more-and-more difficult techniques. Now I'm working on creating a global collection of an object class I've defined.

I have defined: AACurves class, a collection with methods Add, Remove, Clear, Item, and property Count.
AACurve class, an object that has vPoints(360,2) as the property and methods CreateCPICurve and GetCPIfromCurve. These functions work and build the object as they're supposed to.
Now at the module level I'm trying to simply add and retrieve an AACurve object from the AACurve class. Here are the relevant code snippets:

Dim cGlobalCurves As New AACurves

Public Function AACreateCPICurve(WhatToCallIt As String, vSpotDate As Date, vSpotIndex As Double, vvDates As Range, vvRates As Range)

Dim vCurve As New AACurve

vCurve.CreateCPICurve SpotDate:=vSpotDate, SpotIndex:=vSpotIndex, vDates:=vvDates, vRates:=vvRates

cGlobalCurves.Add CurveObject:=vCurve, IndexName:=WhatToCallIt

AACreateCPICurve = WhatToCallIt

End Function

Public Function AAtestgetfromcurve(curvename As String, crvdate As Date)

Dim vCurve As AACurve

Set vCurve = cGlobalCurves.Item(curvename)

AAtestgetfromcurve = vCurve.GetCPIfromCurve(crvdate)

End Function


So, the first function seems to work...and if I use .GetCPIfromCurve in the first function then I get the correct answer back from vCurve. But I'm unable to retrieve the object with the second function. I think it's something to do with the way I'm using the Item method. In AACurves, I've defined the Item method like this:

Public Function Item(IndexName As Variant)
cCurves.Item Index:=IndexName
End Function


The execution of the module-level code seems to end in this function rather than returning to the AAtestgetfromcurve function, so I must be doing something wrong with the syntax?

I'm sure the overall code is pretty ugly-looking to seasoned veterans, but I'm actually pretty pleased with myself. Three months ago I'd never written anything more-elaborate than simple calculator functions...so in other words, don't worry about hurting my feelings by telling me I'm a dolt for not knowing this. I KNOW!

Thanks,

Mike
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
troubleshot a bit more...

I appear to be getting an "object does not support this property or method" error in my collection/class module. The relevant code is:

Public IndexName

Dim cCurves As New Collection

Public Function Item(IndexName As Variant)
Item = cCurves.Item(IndexName)
End Function

Any ideas?

Thx,

Mike
 
Upvote 0

Forum statistics

Threads
1,206,755
Messages
6,074,756
Members
446,083
Latest member
kfunt

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