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