
NPV Function | 381
The Language
Reference
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Example
This sample displays the amount of time needed to pay off a credit card. It uses the
NPer function to determine the length of time required.
Public Sub HowLongToPay( )
' ----- Detail the extent of a debt.
Dim interestRate As Double
Dim currentBalance As Double
Dim monthlyPayment As Double
Dim totalPeriods As Integer
Try
currentBalance = CDbl(InputBox("Credit card balance."))
monthlyPayment = CDbl(InputBox("Monthly payment."))
interestRate = CDbl(InputBox("Monthly interest rate " & _
"(use 0.05 for 5%)."))
totalPeriods = CInt(NPer(interestRate, -monthlyPayment, _
currentBalance, 0#, DueDate.BegOfPeriod))
MsgBox("Your credit card balance will be paid in " & _
totalPeriods & " months. That's " & _
Int(totalPeriods / 12) & " years and " & _
(totalPeriods Mod 12) & " months.")
Catch e As System.Exception
MsgBox("Unable to compute period because of error " & _
e.Message)
End Try
End Sub
See Also
FV Function, IPmt Function, NPV Function, Pmt Function, PPmt Function, PV Func-
tion, Rate Function
NPV Function
Class
Microsoft.VisualBasic.Financial
Syntax
Dim result As Double = NPV(rate, valueArray())
rate (required; Double)
The discount rate over the period, expressed as a decimal percent
valueArray( ) (required; array of Double)
An array of cash-flow ...