calculating interest

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lab3terch
    New Member
    • Oct 2006
    • 22

    #1

    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_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles cmdCompute.Clic k
    Dim amount As Double
    Dim begindate As Integer
    Dim enddate As Integer

    amount = CDbl(TxtInitial Amount.Text)

    begindate = DateTimePickerF ormat.Short
    enddate = DateTimePickerF ormat.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.
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by lab3terch
    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_Clic k(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles cmdCompute.Clic k
    Dim amount As Double
    Dim begindate As Integer
    Dim enddate As Integer

    amount = CDbl(TxtInitial Amount.Text)

    begindate = DateTimePickerF ormat.Short
    enddate = DateTimePickerF ormat.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

    Comment

    • lab3terch
      New Member
      • Oct 2006
      • 22

      #3
      Thank you so much for your guidance! Works fine now and I have learned something new!!

      Comment

      Working...