By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,594 Members | 2,062 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,594 IT Pros & Developers. It's quick & easy.

calculating interest

P: 22
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
Share this Question
Share on Google+
2 Replies


100+
P: 1,646
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

P: 22
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.