Hello, I have a libreoffice basic programming question.
This is a function i want to use to predict the amount of money lost inflation after a number of years. option compatible
Function INFLATION_ADJUSTMENT(ParamArray xData(),ParamArray yData(),AMT,year) As Double
dim r as single
dim r0 as single
dim Amplitude as single
dim Period as single
dim delta_X as single
dim delta_Y as single
dim Y as single
dim H as single
dim V as single
dim Inflation_Rate0 as single
dim Inflation_Rate as single
delta_X = xData(1)-xData(0)
delta_Y = yData(1)-yData(0)
Y = delta_Y/delta_X REM The Derivative of y
Amplitude = Math.SQRT(yData(0)^2+Y^2)
Period = 2*Math.PI()/(UBOUND(xData))
H = Math.ASIN(yData(0)/Amplitude)
REM The Average of the yData = the verticle shift constant
For n = 0 to UBOUND(xData)
V = V + yData(n)/UBOUND(xData)
Next n
For i = 1 to year
Inflation_Rate0 = (Amplitude*Math.SIN(Period*(0)+H)+V)
Inflation_Rate = (Amplitude*Math.SIN(Period*(i)+H)+V)
r0 = AMT*Inflation_Rate0/100
r = r0 + r*Inflation_Rate/100
Next i
INFLATION_ADJUSTMENT = r
End Function
As you may know, I am getting an error on the line of code where I try to compute xData(1)-xData(0). The Error is: Inadmissible Value or Data Type. Index out of defined range.Any way I could make this better?
which error? and how are you calling the function?
The Error is: Inadmissible Value or Data Type. Index out of defined range.
quoting myself:
I am calling the function in the from within the spreadsheet as option compatible. I hope that helped.
sigh... no that haven't helped. If I were asked how I call a function, I'd try to provide arguments, and context, like "I have this in A1: XX; A2: YY; A3: MY_FUNCTION(A1; A2; 13)"...
Well, The function is not in a procedure or anything like that. It was just meant to be a simple macro function.
Then what do you expect the function's arguments to be? your code tries to get the arguments' values, namely (in the failing line) elements of array xData - but where should it get the data from, if you haven't provided the arguments?
Okay. for the arguments, I was putting in for xData values 0 to 22 with an increment of 1. the yData is just the function result of the xData values in the spreadsheet. I called it in the spreadsheet as INFLATION_ADJUSTMENT(A1:A22, B1:B22, C2, D2).
so, please make it crystal clear here:
=INFLATION_ADJUSTMENT(A1:A22, B1:B22, C2, D2)
is in what cell?the y data is 2+cos(A1). 2+cos(A2) .....etc. C2 = 15000 D2 = 20.