請問一下,
當我單獨執行 function pvpv的時候,輸入變數可以得到結果;
但當我利用sub中呼叫function的時候,
就會在以下程式碼中的
j = j + Round(CF / ((1 + r) ^ i), 2)
出現錯誤訊息,"溢位"
是不是我的sub觀念弄錯了,請高手指正,謝謝.
-------------------------------------------------------------------
Sub countpv()
CF = InputBox("enter the cash flow value", "pv calc", "100")
Worksheets("sheet1").Cells(2, 2) = CF
r = InputBox("enter the interest rate", "pv calc", "0.01")
Worksheets("sheet1").Cells(3, 2) = r
n = InputBox("cash flow entered:" & CF & Chr(10) & _
"interest rate entered " & FormatPercent(r, "2") & Chr(10) & _
"enter the number of periods : ", "pv calc", "10")
Worksheets("sheet1").Cells(4, 2) = n
Call pvpv(CF, r, n)
End Sub
-------------------------------------------------------------------
Function pvpv(CF, r, n) As Double
Dim i, j As Double
i = 1
j = 0
Do While i <= n
j = j + Round(CF / ((1 + r) ^ i), 2)
i = i + 1
Loop
pvpv = j
MsgBox "the pv is :" & pvpv, vbOKOnly, "pv calc"
Worksheets("sheet1").Cells(5, 2) = pvpv
End Function
---------------------------------------------------------------------
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 193.10.51.216