View Full Version : Function returns empty array
MamboKing
06-27-2008, 04:29 PM
Could someone please help?
Although I verified that Vals_M() contains valid non-zero data, when I run PiPayOff() it comes out all zero on the Excel sheet.
I run it through the regular Ctrl-Shft-Enter.
I need PiPayOff() to return the Vals_M() array.
Why this does not work? Any hint?
Thank a Lot!
Function PiPayOff(NS%) As Double()
Dim Vals_M() As Double
ReDim Vals_M(NS)
.
.
.
PiPayOff = Vals_M
End Function
mikerickson
06-27-2008, 08:28 PM
I see no error, I would expect the posted code to return an empty array.
If it were dimmed as Variant it would also return the same value.
MamboKing
06-27-2008, 09:19 PM
mikerickson, thanks for replying.
Why do you say
>> I would expect the posted code to return an empty array
I hope you would expect PiPayOff() to return the Vals_M() array (which is not empty, as matter of facts).
Right?
Just to get on the same page... :o)
Best Regards
mikerickson
06-27-2008, 09:23 PM
It was a observation that, lacking the complete code of the function, any proposed solution would be guessing.
How'd my guess work out for you?
MamboKing
06-27-2008, 09:34 PM
Understood.
Bob Phillips
06-28-2008, 01:28 AM
Function PiPayOff(NS%) As Variant
Dim Vals_M
ReDim Vals_M(1 To NS)
.
.
.
PiPayOff = Application.Transpose(Vals_M)
End Function
MamboKing
06-28-2008, 07:40 AM
XLD, Thanks a lot. It works.
Any chance to keep the function As Double?
With PiPayOff(NS%) As Double it does not work...
I'm reluctant to make it Variant.
Bob Phillips
06-28-2008, 08:23 AM
Don't be, VBA will cast its sub-type as required, so it will not cause a problem.
Simon Lloyd
06-28-2008, 11:49 AM
The Great "El Xid" mind reader extrodinaire!
Bob Phillips
06-28-2008, 12:01 PM
The Great "El Xid" mind reader extrodinaire!
No, not really. I just write lots of functions that return arrays.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.