-
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.
-
Re: Interest Calculator Help
change the statement that calcs the monthly payment to:
VB Code:
If dblMthInterestRate = 0 Then
curMonthlyPayment = curPrincipal / intMonths
Else
curMonthlyPayment = curPrincipal * (dblMthInterestRate / (1 - (1 + dblMthInterestRate) ^ -intMonths))
End If
Rock on ...
-
Re: Interest Calculator Help
curMonthlyPayment is still at value of 0...
-
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")
-
Re: Interest Calculator Help
Are your variables defined someplace?
What is in txtAmount?
-
Re: Interest Calculator Help
Do the other textboxes still have values? Can you post the project?
-
1 Attachment(s)
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 ;)
-
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.
-
1 Attachment(s)
Re: Interest Calculator Help
-
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 :cool:
-
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 :cool:
You don't need to.
-
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 :cool:
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! :)
-
Re: Interest Calculator Help
The form you posted did not have the suggested correction.
-
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?
-
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"
-
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?
-
Re: Interest Calculator Help
What are ListViews? I am a beginner so I don't know too much yet.
-
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?
-
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)
-
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.
-
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:
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)
[b]If dblMthInterestRate = 0 Then
curMonthlyPayment = curPrincipal / intMonths
Else[/b]
curMonthlyPayment = curPrincipal * (dblMthInterestRate / (1 - (1 + dblMthInterestRate) ^ -intMonths))
[b]End If[/b]
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
End Sub
-
Re: Interest Calculator Help
Mine still doesn't work, when you run the program, what are you getting for total interest paid?
-
1 Attachment(s)
Re: Interest Calculator Help
-
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"
-
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.
-
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?
-
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)?
-
Re: Interest Calculator Help
I think one way would be
txtTotalInterest = (curMonthlyPayment * intMonths - Val(txtAmount))
which is the total amount paid minus the principle.
-
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! :bigyello:
-
Re: Interest Calculator Help
OK. If you decide to use the ListView change the initial column width settings to
VB Code:
Set clmX = lvDisplay.ColumnHeaders.Add(, , "Year", 800)
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:
If lvDisplay.ListItems.Count > 6 Then
lvDisplay.ColumnHeaders(2).Width = 1520
End If