Why does My Macro Function give error: Inadmissible value or data type. Index out of defined range.

Edited by @Ratslinger for clarity:

Function INFLATION_ADJUSTED(optional x(),optional y(),optional AMT, optioanal Future_Year) as double
        REM predicts the amount adjusted for inflation
        dim Amplitude as double
        dim Delta as double
        dim H as double
        dim V as double 
        dim Period as double 
        dim r as double
        dim Inflation_Rate as double
        Delta = ((y(1,1)-y(0,1)))
        Amplitude = scr(y(0,1)^2 - Delta^2)
        Period = PI()/UBound(x)
        H = ASIN(y(0,1)/Period)
        V = 0
        For n = 0 to x
            V = V + y(n,1)/UBound(x)
        Next n
        For i = 0 to Future_Year
            Inflation_Rate = (Amplitude*SIN(Period*(i)+H)+V)
            r = AMT*(1-Inflation_Rate/100)
        Next i
    End Function

Delta = (y(1,1)-y(0,1)) gives the inadmissible data type: Index out of defined Range error. when I Try to Call the function in my spreadsheet.


This seems to have been discussed already in a past post here → Hello, I have a libreoffice basic programming question.