# mortgage calculator

• (2 Pages)
• 1
• 2

## 16 Replies - 26544 Views - Last Post: 01 October 2008 - 02:01 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=65195&amp;s=cec4394257f10e2fbba7d06171a32176&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 milton7888

Reputation: 1
• Posts: 28
• Joined: 11-September 08

# mortgage calculator

Posted 26 September 2008 - 09:13 AM

i have to make a mortgage calculator in vb 2005

there are 6 input text boxes :::: home value, loan amount, term(years), home insurance, property tax, and interest rate
and one read only text box that is monthly payment....

# P = principal, the initial amount of the loan
# I = the annual interest rate (from 1 to 100 percent)
# L = length, the length (in years) of the loan, or at least the length over which the loan is amortized.

The following assumes a typical conventional loan where the interest is compounded monthly. First I will define two more variables to make the calculations easier:
# J = monthly interest in decimal form = I / (12 x 100)
# N = number of months over which loan is amortized = L x 12

Okay now for the big monthly payment (M) formula, it is:

M = P x ( J/(1-(1-J)^-N)))

i can not get these numbers to come out correctly.....i am not very good at math.....

can someone please send me code for just the calculations on how to do this....

Is This A Good Question/Topic? 0

## Replies To: mortgage calculator

### #2 PsychoCoder

Reputation: 1659
• Posts: 19,853
• Joined: 26-July 07

## Re: mortgage calculator

Posted 26 September 2008 - 10:57 AM

[rules][/rules]

Sorry, we're not just going to send you the code. We will help as soon as you show us what you've done to solve this, but we're not going to do this for you

### #3 jacobjordan

• class Me : Perfection

Reputation: 115
• Posts: 1,499
• Joined: 11-June 08

## Re: mortgage calculator

Posted 26 September 2008 - 11:08 AM

Quite honestly, what code? You already have the equation, and coding an equation is literally just copy/pasting. Like Mr. [rules][/rules] uh, i mean PsychoCoder said, show us an attempt you already made, that way we can see what is going on.

### #4 milton7888

Reputation: 1
• Posts: 28
• Joined: 11-September 08

## Re: mortgage calculator

Posted 26 September 2008 - 07:59 PM

its a matter of i don't understand the formula there are 6 input boxes, but i don't use all them in the mortgage formula...so what r they for, i guess theres something im not understanding , im just not sure what...thanks for any input or help

```Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim p As Double
Dim i As Double
Dim l As Double
Dim m As Double
Dim j As Double
Dim n As Double

i = txtinterest.Text
p = txtloan.Text
l = txtterm.Text

j = i / (1200)
n = l * 12

m = (p * (j / (1 - (1 + j) ^ -n)))

txtpayment.Text = CDbl(m)

End Sub
End Class
```

This post has been edited by milton7888: 26 September 2008 - 08:01 PM

### #5 jacobjordan

• class Me : Perfection

Reputation: 115
• Posts: 1,499
• Joined: 11-June 08

## Re: mortgage calculator

Posted 27 September 2008 - 12:37 PM

What is going wrong? I made a little version of your app myself using your code, and it worked fine. By fine, i mean it spit out some numbers when i typed in random values. I don't do money calculations, so i don't know what to expect from this. It looks like you coded the equation correctly, so please explain what is going wrong in a bit more detail.

Reputation: 7
• Posts: 144
• Joined: 23-September 08

## Re: mortgage calculator

Posted 27 September 2008 - 02:12 PM

Going to admit i am also a little confused.

You said there is 6 inputboxes, from this code i cannot see how that would be necessary.
From what you have posted, i can only see the need for four.

txtLoan, txtInterest, txtTerm and txtPayment

If by input boxes you mean your variables (i am not calling you an idiot, im simply assuming a mistake could possibly be made and there are 6 variables) well if you read the code, its clear to see they are all being used.

```n = l * 12

```

Term should be inputted as yearly. I mention this as it could possibly cause problems, maybe this is the error?

I have also built your application, but instead of making every input box i simply change the values.
debug your code, for the values, have txtinterest at 10, txtloan at 4000 and txtterm at 2. This would be a £4000 loan over a period of 2 years at 10%. Your txtpayment should say: 184.579705350067

Maybe this is your problem? then simply change:

``` m = (p * (j / (1 - (1 + j) ^ -n)))

txtpayment.Text = CDbl(m)
```

To:

```		m = Math.Round((p * (j / (1 - (1 + j) ^ -n))), 2)
payment.Text = CStr(m)

```

Hope it helps

Oops forgot to say why,

The Math.Round (Number, Dec Points) expression, well it rounds 'number' to however many decimal points you state with 'dec point'.

Anyway, i hope i've solved your problem in their somewhere

### #7 Damage

• Lord of Schwing

Reputation: 299
• Posts: 1,989
• Joined: 05-June 08

## Re: mortgage calculator

Posted 27 September 2008 - 04:31 PM

as adam r said you've got six text boxes for

Quote

home value, loan amount, term(years), home insurance, property tax, and interest rate

but if your only using 3 of the inputs why do you need the other three?

Although i have no idea how to work out the mortgage value, do you need to take into account those other factors? Maybe your not getting the right output is because your not including the tax and insurance and initial home value. But from just having a look at an example i'd say the formula is right. What sample data are you using? have a look here
http://www.sorted.or...ments/page2.php
and try use your data and see how it matches up against the output you get from you app

but my two cents is : try using more descriptive variable names when coding. It can save you a lot of headache and it makes it a lot easier for other people to read and help. Labeling things p and j etc is just painful

This post has been edited by Damage: 27 September 2008 - 04:46 PM

### #8 Damage

• Lord of Schwing

Reputation: 299
• Posts: 1,989
• Joined: 05-June 08

## Re: mortgage calculator

Posted 27 September 2008 - 05:07 PM

Quote

Many readers, for reasons of their own, request the algebraic formulas used to calculate the monthly payment and loan balance on amortized mortgages. Here they are:

The following formula is used to calculate the fixed monthly payment (P) required to fully amortize a loan of L dollars over a term of n months at a monthly interest rate of c. [If the quoted rate is 6%, for example, c is .06/12 or .005].

P = L[c(1 + c)n]/[(1 + c)n - 1]

The next formula is used to calculate the remaining loan balance ( B ) of a fixed payment loan after p months.

B = L[(1 + c)n - (1 + c)p]/[(1 + c)n - 1]

try this

This post has been edited by Damage: 27 September 2008 - 05:14 PM

### #9 milton7888

Reputation: 1
• Posts: 28
• Joined: 11-September 08

## Re: mortgage calculator

Posted 28 September 2008 - 05:59 AM

i tried all of ur guys stuff, it did help, i got a rounded number and im getting a closer output now, but im still off by like 350 bucks, im sure its becaus eim not using all the variables but ive tried and cant seem to use tthem correctly,
i must be missing some formulas or something.....

i sent a few of u a message with some example numbers, let me know if ne of u can help an ill send you some example numbers.....thanks

math blows

### #10 jacobjordan

• class Me : Perfection

Reputation: 115
• Posts: 1,499
• Joined: 11-June 08

## Re: mortgage calculator

Posted 28 September 2008 - 08:44 AM

I love math.

I'll take a look at the examples you sent me. I'm a bit busy at the moment, so i'll get to it in about an hour or two.

### #11 milton7888

Reputation: 1
• Posts: 28
• Joined: 11-September 08

## Re: mortgage calculator

Posted 28 September 2008 - 06:11 PM

jacobjordan, on 28 Sep, 2008 - 08:44 AM, said:

I love math.

I'll take a look at the examples you sent me. I'm a bit busy at the moment, so i'll get to it in about an hour or two.

still ahvent got ne help....is ne one gonna help?

### #12 jacobjordan

• class Me : Perfection

Reputation: 115
• Posts: 1,499
• Joined: 11-June 08

## Re: mortgage calculator

Posted 28 September 2008 - 08:35 PM

Sorry. I've been really busy today. I've been writing a huge tutorial for Dream In Code, working on several programs, and had a personal narrative to write for school. I really haven't had time for just browsing on DIC and helping people. However, like AdamR said, you said you had 6 input text boxes, however you only have 3 variables for your equation, so what are the other 3 for? I would love to help you, but i am very confused myself.

### #13 milton7888

Reputation: 1
• Posts: 28
• Joined: 11-September 08

## Re: mortgage calculator

Posted 28 September 2008 - 09:15 PM

jacobjordan, on 28 Sep, 2008 - 08:35 PM, said:

Sorry. I've been really busy today. I've been writing a huge tutorial for Dream In Code, working on several programs, and had a personal narrative to write for school. I really haven't had time for just browsing on DIC and helping people. However, like AdamR said, you said you had 6 input text boxes, however you only have 3 variables for your equation, so what are the other 3 for? I would love to help you, but i am very confused myself.

hahah, yeah dont worry, about it, im lost, im slowly, giving up.....ill figure something out,

if ne one else wants to help or has input let me know....

Reputation: 7
• Posts: 144
• Joined: 23-September 08

## Re: mortgage calculator

Posted 29 September 2008 - 06:31 AM

Milton, you mentioned about your professor, so i guess this is a educational project.

EXACTLY what information where you given ?

### #15 dbasnett

Reputation: 117
• Posts: 646
• Joined: 01-October 08

## Re: mortgage calculator

Posted 01 October 2008 - 12:41 PM

```	 Private Sub loan()
Dim L As Double = 125000D 'loan amount
Dim rate As Double = 6.375D  'interest rate
Dim c As Double = (rate / 100D) / 12 'monthly interest rate
Dim Nyear As Double = 30 'length of loan in years
Dim n As Double = Nyear * 12 'length of loan in months
Dim P As Double 'the payment
P = Microsoft.VisualBasic.Financial.Pmt(c, n, -L)
End Sub

```