Results 1 to 8 of 8

Thread: [RESOLVED] Calculate Interest?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    Resolved [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:
    1. Private Sub cmdCalculate_Click()
    2.  
    3.     'Proform calculations
    4.     txtProfit.Text = Val(txtAccountbalance.Text) * 4.5 / 100 / Val(txtDuration.Text)
    5.     txtNewbalance.Text = Val(txtProfit.Text) + Val(txtAccountbalance.Text)
    6.    
    7.     'To correct values to 2 decimal places since it is money.
    8.     txtNewbalance.Text = Format(txtNewbalance.Text, "currency")
    9.     txtProfit.Text = Format(txtProfit.Text, "currency")
    10.    
    11. End Sub

    it doesnt work really well.. could someone tell me wad code to write?

    My screenshot is attached below:

  2. #2
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Melbourne, Australia
    Posts
    415

    Re: Calculate Interest?

    Try this:
    VB Code:
    1. Private Sub cmdCalculate_Click()
    2. txtNewBalance.Text = txtAccountBalance.Text
    3. txtProfit.Text = 0
    4. For i = 1 To Val(txtDuration.Text)
    5.     txtNewBalance = Val(txtNewBalance) + (Val(txtNewBalance.Text) * 4.5 / 100 / 12)
    6. Next
    7. txtNewBalance = Format(txtNewBalance.Text, "currency")
    8. txtProfit = Format(txtNewBalance - txtAccountBalance.Text, "currency")
    9. End Sub

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    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.

  4. #4
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    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.

  5. #5
    Lively Member
    Join Date
    Sep 2005
    Location
    Tijuana,Mexico
    Posts
    109

    Re: Calculate Interest?

    I don't know why... but what Rob says should work... anyway try this way around:

    VB Code:
    1. Private Sub cmdCalculate_Click()
    2. dim i as long  '*** Maybe that was the problem of not being defined...
    3. txtNewBalance.Text = txtAccountBalance.Text
    4. txtProfit.Text = 0
    5. For i = 1 To Val(txtDuration.Text)
    6.     txtNewBalance = Val(txtNewBalance) * (1 + 4.5 /(100*12))
    7. Next
    8. txtNewBalance = Format(txtNewBalance.Text, "currency")
    9. txtProfit = Format(txtNewBalance - txtAccountBalance.Text, "currency")
    10. End Sub

  6. #6
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Re: Calculate Interest?

    FV = P(1 + r)n

    Where:
    FV = Future Value
    P = Principle
    r = interest rate (decimal form)
    n = compounding periods

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Calculate Interest?

    * sorry posted wroing formula ^^
    Last edited by leinad31; Oct 27th, 2006 at 12:25 PM.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Oct 2006
    Posts
    74

    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
  •  



Click Here to Expand Forum to Full Width