martin2k

ForumsVB6GamesSoftwareDirectoryHTMLArticlesBlogContact

I need code to calculate interest on a savings account


 

Home

Read and add posts to the Visual Basic 6.0 Forums

Download some of my programs and OCXs

Read the Tips here

The old style forum is still available here

Contact


 

Question

From: Bratmil15
Date: Sunday 04 November 2001 11:49 PM
Subject: I need Help, could you email me back with this info?
Question: Hi,

I am currently taking a class in visual basic . I have to create an application that computes the future value of an investment at the end of each year. The user specifies the initial amount, the interest rate, and the number of compounding periods per year. I used a dropdown combo box for the interest rate for values ranging from 5 percent to 12 percent in 1 percent increments. For periods per year, I used a simple combo box with 1, 4, 12, and 365 as the valid values. The user will specify the first and last yr to be displayed. I used a list box that will display the yearly values. I have to use FV() function to perform the calculations. The variables I declared are:

Dim FVal As Currency
Dim FirstYr As Integer
Dim LastYr As Integer
Dim Amount As Currency
Dim Rate As Currency
Dim PPYr As Integer

This is all I have done so far, I don't even know where to begin after I declared these variables. I know for this I will probably have to use a loop, but how to do it, my brains complete mush on this. Is there anyway you could guide me in some way on this, I'd greatly appreciate it. Thanks, Millie

Answer by Martin Allen:

If you told me what formula this would require, then I could write it in VB code for you.

I think it might be (for one year):

value * (percent / 100) = interest

interest + value = result

E.g. if someone invested $850 with an interest rate of 12%, they would end up with $952 after 1 year.

I might have the correct answer here, but test it out to see if it gives accurate results, because I am not 100% sure:

Dim FVal As Currency
Dim FirstYr As Integer
Dim LastYr As Integer
Dim Rate As Currency
Dim PPYr As Integer

FVal = 100
FirstYr = 1
LastYr = 5
Rate = 10
PPYr = 1

Rate = Rate / PPYr

Do Until FirstYr = LastYr * PPYr
    tmp = FVal * (Rate / 100)
    FVal = tmp + FVal
    FirstYr = FirstYr + 1
Loop

FV = FVal


blog comments powered by Disqus
Martin Allen 1999 - 2011.  Last updated Friday 12 August 2011 11:52:55 PM +0100.