|
-
Oct 27th, 2006, 10:50 AM
#1
Thread Starter
Lively Member
[RESOLVED] Calculate Interest?
Greetings all,
I'm trying to get this to work properly, its to calculate profit and new account balance as u put the money in a bank for interest.
For example, if we have a balance of $1000 in our account and we wish to know how much we will have in the account after 3 months using an annual interest rate of 4.5% compounded monthly:
After first month: interest earned = $1000 * 4.5 / 100 / 12 = $3.75
new balance = $1000 + $3.75 = $1003.75
After second month: interest earned = $1003.75 * 4.5 / 100 / 12 = $3.76
new balance = $1003.75 + $3.76 = $1007.51
After third month: interest earned = $1007.51 * 4.5 / 100 / 12 = $3.78
new balance = $1007.51 + $3.78 = $1011.29
So, after 3 months we will have $1011.29 in our account and we will have earned $11.29.
My code is:
VB Code:
Private Sub cmdCalculate_Click()
'Proform calculations
txtProfit.Text = Val(txtAccountbalance.Text) * 4.5 / 100 / Val(txtDuration.Text)
txtNewbalance.Text = Val(txtProfit.Text) + Val(txtAccountbalance.Text)
'To correct values to 2 decimal places since it is money.
txtNewbalance.Text = Format(txtNewbalance.Text, "currency")
txtProfit.Text = Format(txtProfit.Text, "currency")
End Sub
it doesnt work really well.. could someone tell me wad code to write?
My screenshot is attached below:
-
Oct 27th, 2006, 11:05 AM
#2
Hyperactive Member
Re: Calculate Interest?
Try this:
VB Code:
Private Sub cmdCalculate_Click()
txtNewBalance.Text = txtAccountBalance.Text
txtProfit.Text = 0
For i = 1 To Val(txtDuration.Text)
txtNewBalance = Val(txtNewBalance) + (Val(txtNewBalance.Text) * 4.5 / 100 / 12)
Next
txtNewBalance = Format(txtNewBalance.Text, "currency")
txtProfit = Format(txtNewBalance - txtAccountBalance.Text, "currency")
End Sub
-
Oct 27th, 2006, 11:32 AM
#3
Thread Starter
Lively Member
Re: Calculate Interest?
whats i? it says variable not defined..
how to make it loop like wad it says?
After first month: interest earned = $1000 * 4.5 / 100 / 12 = $3.75
new balance = $1000 + $3.75 = $1003.75
After second month: interest earned = $1003.75 * 4.5 / 100 / 12 = $3.76
new balance = $1003.75 + $3.76 = $1007.51
After third month: interest earned = $1007.51 * 4.5 / 100 / 12 = $3.78
new balance = $1007.51 + $3.78 = $1011.29
So, after 3 months we will have $1011.29 in our account and we will have earned $11.29.
-
Oct 27th, 2006, 11:41 AM
#4
PowerPoster
Re: Calculate Interest?
If you want something where you can actually use only one calculation for any number of months, that's a challenge but possible...if I had VB installed I'd have a go but I don't :-)
I think that (if you didn't want compound interest) it can be achieved using something along the lines of ((100 + ([yearly interest /12]*[months]))/100)*money
That should do it if it wasn't compound...if yearly interest was 12% (for simplicity sake) it would mean that for a 5 month interest calculation on $1000 you would get $1000 x 1.05 which is $1050 (just mental arithmatic, I'm not actually testing this)...doing COMPOUND interest is more of a hassle and the easiest way would be to use a loop.
I *think* there might be a way to multiply a number to get a compound interest modification value (that you could use to multiply the base cash value to get the end result) but without using VB I won't be able to work it out :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Oct 27th, 2006, 12:07 PM
#5
Lively Member
Re: Calculate Interest?
I don't know why... but what Rob says should work... anyway try this way around:
VB Code:
Private Sub cmdCalculate_Click()
dim i as long '*** Maybe that was the problem of not being defined...
txtNewBalance.Text = txtAccountBalance.Text
txtProfit.Text = 0
For i = 1 To Val(txtDuration.Text)
txtNewBalance = Val(txtNewBalance) * (1 + 4.5 /(100*12))
Next
txtNewBalance = Format(txtNewBalance.Text, "currency")
txtProfit = Format(txtNewBalance - txtAccountBalance.Text, "currency")
End Sub
-
Oct 27th, 2006, 12:14 PM
#6
Re: Calculate Interest?
FV = P(1 + r)n
Where:
FV = Future Value
P = Principle
r = interest rate (decimal form)
n = compounding periods
-
Oct 27th, 2006, 12:19 PM
#7
Re: Calculate Interest?
* sorry posted wroing formula ^^
Last edited by leinad31; Oct 27th, 2006 at 12:25 PM.
-
Oct 27th, 2006, 12:28 PM
#8
Thread Starter
Lively Member
Re: Calculate Interest?
ahh thank you so much guys very much appreciated.
RATED!!!!!!
Last edited by eklips; Oct 27th, 2006 at 12:33 PM.
Hacking is like a drug, one taste and you can't stop. Unless you fill it up with another drug.. Learning.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|