outerspace
01-02-2010, 10:22 AM
I am having a problem with the following function I have written in VBA.
Function Price(GCurve As Variant, Timeline As Variant, nsims As Integer)
Dim k As Integer
Dim nc As Integer
Dim SimRate As Double
ReDim Output(1 To 1, 1 To nsims) As Double
nc = GCurve.Rows.Columns.Count
SimRate = 0
tempCurve = GCurve
For k = 1 To 3
Dummy = SimCurve(GCurve, Timeline, 1 / 20, 100)
SimRate = SimRate + Dummy(1, 11)
Output(1, k) = SimRate / k
GCurve = tempCurve
Next k
Price = Output
If I replace the loop by from k=1 to 1 (or from k=2 to 2) everything works fine. I have isolated the problem to the lines
Dummy = SimCurve(GCurve, Timeline, 1 / 20, 100)
Dummy = SimCurve(GCurve, Timeline, 1 / 20, 100)
I can't see why I shouldn't be allowed to call this function twice, even within another function. SimCurve returns an array, and the structure is as follows:
Function SimCurve(FCurve As Variant, Timeline As Variant, _
tstep As Double, nsteps As Integer) As Variant
(alter FNew based on input)
FCurve = FNew
SimCurve = FCurve
End Function
Any ideas as to what could be going wrong? :)
Function Price(GCurve As Variant, Timeline As Variant, nsims As Integer)
Dim k As Integer
Dim nc As Integer
Dim SimRate As Double
ReDim Output(1 To 1, 1 To nsims) As Double
nc = GCurve.Rows.Columns.Count
SimRate = 0
tempCurve = GCurve
For k = 1 To 3
Dummy = SimCurve(GCurve, Timeline, 1 / 20, 100)
SimRate = SimRate + Dummy(1, 11)
Output(1, k) = SimRate / k
GCurve = tempCurve
Next k
Price = Output
If I replace the loop by from k=1 to 1 (or from k=2 to 2) everything works fine. I have isolated the problem to the lines
Dummy = SimCurve(GCurve, Timeline, 1 / 20, 100)
Dummy = SimCurve(GCurve, Timeline, 1 / 20, 100)
I can't see why I shouldn't be allowed to call this function twice, even within another function. SimCurve returns an array, and the structure is as follows:
Function SimCurve(FCurve As Variant, Timeline As Variant, _
tstep As Double, nsteps As Integer) As Variant
(alter FNew based on input)
FCurve = FNew
SimCurve = FCurve
End Function
Any ideas as to what could be going wrong? :)