Results 1 to 30 of 30

Thread: Interest Calculator Help

  1. #1

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Interest Calculator Help

    I'm making an Interest Calculator for a comp prog class and I have everything done except a monthly Interest Rate. I need to display how much you would pay a month for x amount of years and x interest for x amount of dollars. My problem is my variable for monthly interest rate has a value of zero, which messes up all my monthly total payment.

    Here is my code...

    Private Sub chkMonthly_Click()

    'Sends Monthly Payments to lstMonthlyPayments

    intCounter = 1
    curPrincipal = Val(txtAmount)

    lstMonthlyDisplay.AddItem ("Month" & vbTab & "Amount Payed")
    dblMthInterestRate = Val(txtInterest / (12 * 100))
    intMonths = (intYears * 12)

    curMonthlyPayment = curPrincipal * (dblMthInterestRate / (1 - (1 + dblMthInterestRate) ^ -intMonths))

    txtMonthlyPayment = Format(curMonthlyPayment, "$######.00")
    txtTotalInterest = (dblMthInterestRate * intMonths)
    dblMthInterestRate = Format(dblMthInterestRate, "$######.00")

    For intCounter = 1 To (intYears * 12)

    curTotalPayment = (curTotalPayment + curMonthlyPayment)
    curTotalPayment = curTotalPayment + dblMthInterestRate
    lstMonthlyDisplay.AddItem (intCounter & vbTab & Format(curTotalPayment, "$######.00"))

    Next intCounter

    The variable in red is the variable that has no value.

    CAN ANYONE HELP.
    Nick

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Interest Calculator Help

    change the statement that calcs the monthly payment to:
    VB Code:
    1. If dblMthInterestRate = 0 Then
    2.     curMonthlyPayment = curPrincipal / intMonths
    3. Else
    4.     curMonthlyPayment = curPrincipal * (dblMthInterestRate / (1 - (1 + dblMthInterestRate) ^ -intMonths))
    5. End If

    Rock on ...
    "It's cold gin time again ..."

    Check out my website here.

  3. #3

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Interest Calculator Help

    curMonthlyPayment is still at value of 0...
    Nick

  4. #4

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Interest Calculator Help

    Private Sub chkMonthly_Click()

    'Sends Monthly Payments to lstMonthlyPayments

    intCounter = 1
    curPrincipal = Val(txtAmount)

    lstMonthlyDisplay.AddItem ("Month" & vbTab & "Amount Payed")

    If dblMthInterestRate = 0 Then
    curMonthlyPayment = curPrincipal / intMonths
    Else
    curMonthlyPayment = curPrincipal * (dblMthInterestRate / (1 - (1 + dblMthInterestRate) ^ -intMonths))
    End If

    txtMonthlyPayment = Format(curMonthlyPayment, "$######.00")
    txtTotalInterest = (dblMthInterestRate * intMonths)
    dblMthInterestRate = Format(dblMthInterestRate, "$######.00")
    Nick

  5. #5

  6. #6
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Interest Calculator Help

    Do the other textboxes still have values? Can you post the project?
    "It's cold gin time again ..."

    Check out my website here.

  7. #7

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Interest Calculator Help

    yes that is just part of my code all my variables are defined and I have option explicit. txtAmount is a text box when you input the amount of money you need to pay off.

    I attached my form if anyone wants to look at it and play around with it to see whats wrong. My spacing and tabbing may look bad but its the outside that should look good right
    Attached Files Attached Files
    Nick

  8. #8
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Interest Calculator Help

    Didn't you download WinZip? I told you where to get it and how to use it. It is very hard to run most programs if there is only a form. Sometimes it can be done, but only for simple forms.

  9. #9

  10. #10

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Interest Calculator Help

    Yes I already had it, but I didn't know that I could turn files into zip files, I thought it was only to extract zip files. How do I turn the form into the zip file?


    By the way, my form is simple
    Nick

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Interest Calculator Help

    Quote Originally Posted by nickTHEguitarist
    Yes I already had it, but I didn't know that I could turn files into zip files, I thought it was only to extract zip files. How do I turn the form into the zip file?


    By the way, my form is simple
    You don't need to.

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Interest Calculator Help

    Quote Originally Posted by nickTHEguitarist
    Yes I already had it, but I didn't know that I could turn files into zip files, I thought it was only to extract zip files. How do I turn the form into the zip file?


    By the way, my form is simple
    As someone who has difficulty balancing his own checkbook, I'm don't know much about interest calculations, but I can help you zip up a bunch of files.

    Open WinZip, click on New
    You will be prompted to create a new zip file. Navigate to the folder you want to create the zip file in and name it: Nick.zip

    Click Ok
    Now navigate to to the folder containing the files you want to put in the zip file, and, holding down the Ctrl Key, click on each file to add, then Click Add

    And, there you have it!

  13. #13
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Interest Calculator Help

    The form you posted did not have the suggested correction.
    "It's cold gin time again ..."

    Check out my website here.

  14. #14

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Interest Calculator Help

    I know I forgot to save it before I sent it, but it did not work with the correction. I might have put it in wrong. Can you play with it and see if you can figure it out?

    Hack,
    Thanks for the zip help, where is eastpointe in Michigan?
    Nick

  15. #15
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Interest Calculator Help

    Here are several suggestions for you:

    • Change to ListViews rather than Listboxes as the former will allow you to have headings.
    • Disable the checkbox until the amount owed calculations are done
    • Format total interest paid
    • After the amount owed calculation is done, change lblAmountOwed.Caption to "Amount Owed after " & Val(txtYears) & " Years"

  16. #16
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Interest Calculator Help

    Quote Originally Posted by nickTHEguitarist
    I know I forgot to save it before I sent it, but it did not work with the correction. I might have put it in wrong. Can you play with it and see if you can figure it out?

    Hack,
    Thanks for the zip help, where is eastpointe in Michigan?
    Did you see the image I posted?

  17. #17

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Interest Calculator Help

    What are ListViews? I am a beginner so I don't know too much yet.
    Nick

  18. #18
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Interest Calculator Help

    Quote Originally Posted by nickTHEguitarist
    What are ListViews? I am a beginner so I don't know too much yet.
    Hang on a bit and I'll convert one of your listboxes. Until then do you have any comment about my saying that it works for me?

  19. #19
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Interest Calculator Help

    Quote Originally Posted by nickTHEguitarist
    What are ListViews? I am a beginner so I don't know too much yet.
    ListView Tutorial

    (Eastpointe is a suburb of Detroit...East side)

  20. #20

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Interest Calculator Help

    Oh I'm sorry, I didn't see your comment and your pic. Does every aspect of the program work for you, or is it just the yearly interest side? Because the yearly interest works for me also, it's the monthly interest side that doesnt work.
    Nick

  21. #21
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657

    Re: Interest Calculator Help

    When I put the correction in, the calc for zero interest seemed to work. Here is the corrected sub. The code in bold is the only thing I touched ...

    VB Code:
    1. Private Sub chkMonthly_Click()
    2.  
    3.     'Sends Monthly Payments to lstMonthlyPayments
    4.    
    5.         intCounter = 1
    6.         curPrincipal = Val(txtAmount)
    7.        
    8.         lstMonthlyDisplay.AddItem ("Month" & vbTab & "Amount Payed")
    9.         dblMthInterestRate = Val(txtInterest / (12 * 100))
    10.         intMonths = (intYears * 12)
    11.         [b]If dblMthInterestRate = 0 Then
    12.             curMonthlyPayment = curPrincipal / intMonths
    13.         Else[/b]
    14.             curMonthlyPayment = curPrincipal * (dblMthInterestRate / (1 - (1 + dblMthInterestRate) ^ -intMonths))
    15.         [b]End If[/b]
    16.         txtMonthlyPayment = Format(curMonthlyPayment, "$######.00")
    17.         txtTotalInterest = (dblMthInterestRate * intMonths)
    18.         dblMthInterestRate = Format(dblMthInterestRate, "$######.00")
    19.    
    20.     For intCounter = 1 To (intYears * 12)
    21.        
    22.         curTotalPayment = (curTotalPayment + curMonthlyPayment)
    23.         curTotalPayment = curTotalPayment + dblMthInterestRate
    24.         lstMonthlyDisplay.AddItem (intCounter & vbTab & Format(curTotalPayment, "$######.00"))
    25.    
    26.     Next intCounter
    27.    
    28.        
    29.        
    30.    
    31. End Sub
    "It's cold gin time again ..."

    Check out my website here.

  22. #22

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Interest Calculator Help

    Mine still doesn't work, when you run the program, what are you getting for total interest paid?
    Nick

  23. #23

  24. #24

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Interest Calculator Help

    Quote Originally Posted by MartinLiss
    Here a project to try.
    I think we have different versions of visual basic, because mine doesn't like your "columnheaders"
    Nick

  25. #25
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Interest Calculator Help

    Quote Originally Posted by nickTHEguitarist
    Mine still doesn't work, when you run the program, what are you getting for total interest paid?
    I'm getting a value but it's not correct. What your are doing is this

    txtTotalInterest = (dblMthInterestRate * intMonths)

    which to me looks like just a multipication of the rate rather than money paid.

  26. #26
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Interest Calculator Help

    Quote Originally Posted by nickTHEguitarist
    I think we have different versions of visual basic, because mine doesn't like your "columnheaders"
    Are you using VB6? Did you run the project or just the form?

  27. #27

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Re: Interest Calculator Help

    Quote Originally Posted by MartinLiss
    I'm getting a value but it's not correct. What your are doing is this

    txtTotalInterest = (dblMthInterestRate * intMonths)

    which to me looks like just a multipication of the rate rather than money paid.

    So I should make it as txtTotalInterest =(dblMthInterestRate * intMonths + curMonthlyPayment)?
    Nick

  28. #28

  29. #29

    Thread Starter
    Lively Member nickTHEguitarist's Avatar
    Join Date
    Apr 2005
    Location
    Michigan
    Posts
    82

    Resolved Re: Interest Calculator Help

    Ok, thanks for all your help guys. I am going to try and figure the problem in class monday with my teacher. It's easier to get help from someone standing next to you than someone who's hundreds of miles away. THANKS!
    Nick

  30. #30
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Interest Calculator Help

    OK. If you decide to use the ListView change the initial column width settings to

    VB Code:
    1. Set clmX = lvDisplay.ColumnHeaders.Add(, , "Year", 800)
    2.    Set clmX = lvDisplay.ColumnHeaders.Add(, , "AmountOwed", 1800)

    and put this at the end of cmdCalculate which will compensate for the width of the vertical scrollbar (so you don't get an horizontal one).

    VB Code:
    1. If lvDisplay.ListItems.Count > 6 Then
    2.         lvDisplay.ColumnHeaders(2).Width = 1520
    3.     End If

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