467,146 Members | 992 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,146 developers. It's quick & easy.

calculating interest

I am working on a program in which the user enters an amount of money in a textbox, selects a beginning and ending date using the datetimepicker, and then the program calculates the new amount based on an interest rate of 1% compounded monthly. The code I have written is as follows:

Public Class Form1

Private Sub cmdCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCompute.Click
Dim amount As Double
Dim begindate As Integer
Dim enddate As Integer

amount = CDbl(TxtInitialAmount.Text)

begindate = DateTimePickerFormat.Short
enddate = DateTimePickerFormat.Short

Label4.Text = ("You now have " & CDbl(amount * 1.01) & "")


End Sub
End Class

This works fine for 1 month, but I need to be able to determine the number of months between the begindate and the enddate, and then somehow use that figure in the formula so that if, for example, the user selects 3 months the formula will be amount * 1.01*1.01*1.01.
I know what I need to do, but don't seem to be able to get there!! Any guidance would be appreciated.
Nov 4 '06 #1
  • viewed: 1184
Share:
2 Replies
1GB
I am working on a program in which the user enters an amount of money in a textbox, selects a beginning and ending date using the datetimepicker, and then the program calculates the new amount based on an interest rate of 1% compounded monthly. The code I have written is as follows:

Public Class Form1

Private Sub cmdCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCompute.Click
Dim amount As Double
Dim begindate As Integer
Dim enddate As Integer

amount = CDbl(TxtInitialAmount.Text)

begindate = DateTimePickerFormat.Short
enddate = DateTimePickerFormat.Short

Label4.Text = ("You now have " & CDbl(amount * 1.01) & "")


End Sub
End Class

This works fine for 1 month, but I need to be able to determine the number of months between the begindate and the enddate, and then somehow use that figure in the formula so that if, for example, the user selects 3 months the formula will be amount * 1.01*1.01*1.01.
I know what I need to do, but don't seem to be able to get there!! Any guidance would be appreciated.
Hi.
I think I have a grasp of what you want to do. If we just stick with the date part.
You might look up the DateDiff() function.
In terms of your request it might look like this

Dim lngMonths As Long

lngMonths = DateDiff("m", begindate, enddate)

Hope this is useful
Nov 5 '06 #2
Thank you so much for your guidance! Works fine now and I have learned something new!!
Nov 5 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by debi.robarts@gmail.com | last post: by
22 posts views Thread by dos.fishing@gmail.com | last post: by
4 posts views Thread by =?Utf-8?B?TmF2YW5lZXRoLksuTg==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.