Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > Visual Basic Pmt, IPmt, and PPmt functions
 

Visual Basic Pmt, IPmt, and PPmt functions

I'm making a program that uses user input to get a compound interest on a CD and determine whether the user can afford an item they want. The user enters the Principal, the number of years invested, and the interest rate. The program then needs to get the compound interest.The formula for compound interest is Amount = Principal * (1 + InterestRate).If the CD has been invested for more than 1 year then the program needs to be executed for each year with the principal increasing to a new amount each year.
Once the program has the amount the investment is worth the user then supplies the program with the cost of the item they want. The program should then determine if the investment has grown enough for the user to be able to afford the item, and display a message telling them if they can afford it or not.
I'm pretty sure to figure out the compound interest I need to use a Pmt, PPmt, or IPMt function. However I've tried using everyone of them and still can't get the program to work right. Here is the code I have so far. Can anyone tell me what I'm doing wrong? I'm so confused.

Dim intYears As Integer 'Number of years invested

Dim dblRate As Double 'Declares the interst rate as a double

Dim sngNUMBER_YEAR As Single = 1

Dim intCount As Integer 'Counter for the loop

Dim dblPrincipal As Double 'Decalares the Principal as Double

Dim dblInterest As Double

'Get the number of years and calculate the amount of interest

intYears = CInt(txtInvested.Text)

dblPrincipal = CDbl(txtPrincipal.Text)

'Calculate the yearly payments

dblPayment = Pmt(dblRate / sngNUMBER_YEAR, _

intYears, -dblPrincipal)

For intCount = 1 To intYears

'Holds list box output

Dim strOut As String = String.Empty

'Add the year to the output string

strOut = intCount.ToString

dblInterest = IPmt(dblRate / sngNUMBER_YEAR, _

intCount, intYears, -dblPrincipal)

dblAmount = dblPayment + dblInterest

lstDisplay.Items.Add("Year " & intCount.ToString & dblAmount.ToString("c"))

Next


Sam0414  Monday, October 26, 2009 4:53 PM
those functions won't help you with your calculation.

if i understand you, you are trying to calculate the future value of an investment's present value accruing at a fixed interest rate for a specific number of years.

You don't need any of those functions or any looping to calculate this. Just a one line calculation.

Here's some pseudocode for the basic calculation:

principal = 100
interestrate = .05
numberofyears = 10

futurevalue = principal * (1 + interestrate) ^ numberofyears

once you have the futurevalue, you can compare it to the item cost and display your message.

now, if you want to figure out how many years it will take for the user's investment to grow enough to afford the item, you would have to do some looping.
BarbaraR  Friday, October 30, 2009 8:14 PM
those functions won't help you with your calculation.

if i understand you, you are trying to calculate the future value of an investment's present value accruing at a fixed interest rate for a specific number of years.

You don't need any of those functions or any looping to calculate this. Just a one line calculation.

Here's some pseudocode for the basic calculation:

principal = 100
interestrate = .05
numberofyears = 10

futurevalue = principal * (1 + interestrate) ^ numberofyears

once you have the futurevalue, you can compare it to the item cost and display your message.

now, if you want to figure out how many years it will take for the user's investment to grow enough to afford the item, you would have to do some looping.
BarbaraR  Friday, October 30, 2009 8:14 PM

You can use google to search for other answers

Custom Search

More Threads

• How to dim an array made up of other arrays (nested arrays).. Why doesn't this work?
• registered component may not always be installed
• Get Ip address on my logical driver ?
• Does anyone know to connect db2 database in host with vb.net 2005 ?
• Picturebox1.Image and My.Resource
• Listing all instances of a class.
• COM Component in 64 bit ?
• [vb.net 2005] sending a bit from a pc to another in a LAN
• Change VB form Colors
• Scroll text in a label horizontally using VB.net