473,324 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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
2 1368
willakawill
1,646 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

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

Similar topics

25
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to...
0
by: Jason | last post by:
I need help designing a query (or two) in MS Access that will calculate a compounded rate of interest. This would be no problem using a simple FV function if the Interest Rate were constant....
4
by: Veger | last post by:
I'm having some logic trouble (IE: I can't figure out how to do this) I have an assignment in which I need to calculate annual interest. IE: P1 = P0 + P0*INT (interest) = P0*(1+INT) P2 = P1 +...
4
by: Yotam | last post by:
Hi, I need some help with JS. I will be grateful, if you can help me out. I have two date fields (check in, check out) and "number of days" field. I want the script to calculate automatically...
3
by: debi.robarts | last post by:
I am setting up a database to keep track of network leases. I have a field for "original rent" and then fields to capture how it escalates (what % how often). I want to set up fields that give 1)...
22
by: dos.fishing | last post by:
Hello, I'm writing a function that should do the following: /** * Calculate and return fraction of valueA where max fractions is 31. * param valueA A five bit value, 0-31. * param valueB The...
2
by: fatimahtaher | last post by:
Hi, I am new to C# programming and my first assignment requires me to calculate total interest paid on a loan. The user will input the loan, the interest rate per month, and the monthly payment....
10
by: Joseph Geretz | last post by:
I need to calculate miles per degree longitude, which obviously depends on latitude since lines of longitude converge at the poles. Via Google, I've come up with the following calculation: ...
4
by: =?Utf-8?B?TmF2YW5lZXRoLksuTg==?= | last post by:
Say I have a class like, class Sample { public decimal first = 10; public decimal second = 20; } I have initialized it
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.