0
我是VBA的新手,非常感謝您的幫助。在VBA中使用數組的錯誤
我在寫一個自定義函數。我試圖使用數組來存儲for循環的值,並根據它們在數組上的位置來檢索值。 請參考下面的代碼
Function Amounttopay(Original_Principal As Integer, APR As Double, Npayperyear As Integer, term As Integer, Paydone As Integer)
Dim strinitialamount() As Integer
Dim strInterestp() As Integer
Dim strendamount() As Integer
Dim i As Integer
r = (APR/Npayperyear)
n = Npayperyear * term
emi = (Original_Principal * r)/(1 - ((1 + r)^(-1 * n)))
ReDim strinitialamount(n)
ReDim strInterestp(n)
ReDim strendamount(n)
strinitialamount(0) = Original_Principal
strInterestp(0) = (Original_Principal * r)
strendamount(0) = (Original_Principal - (emi - strInterestp(0)))
For i = 1 To (n - 1)
strinitialamount(i) = strendamount(i - 1)
strInterestp(i) = (strinitialamount(i)) * r
strendamount(i) = (strinitialamount(i)) - (emi - strInterestp(i))
Next i
Amounttopay = strendamount(Paydone)
End Function
你從哪裏得到這個錯誤嗎? –
在功能輸出。沒有值只顯示#NUM! – Sam
在你的聲明中,你沒有完全的功能。函數x(...東西)作爲整數。 –