Saturday, March 24, 2012

Newbie getting very frustrated....

Hi. I have been doing html web designs for a few years now. And now i have been trying to work with asp.net. I bought the book Sams Teach Yourself ASp.Net in 24 Hours.

In hour 3 and 4 of the book they have you making a Mortgage Calculator. So i have spent a few days working on this. I cannot seem to get this. I keep getting error after error. And yet when i look at the code, it is typed the same way it is in the lessons. And yet, at the end of the lsessons, it doesn't go into depth or anything about if the project doesnt work, or what happens when you get these errors.

Anyone have this book, that can help me out? I really need to learn this. And i have been told this book is a wastse of myt ime. But it was the only book the Barnes and Nobles had on ASP.Net.

So i guess i am stuck with it. Here is the code...

Sub performCalc_Click(sender As Object, e As EventArgs)
'Specify constant values
Const INTEREST_CALCS_PER_YEAR as Integer = 12
Const PAYMENTS_PER_YEAR as Integer = 12

'Create variables to hold the values entered by the user
Dim P as Double = loanAmount.Text
Dim r as Double = rate.Text / 100
Dim t as Double = mortgageLength.Text

Dim ratePerPeriod as Double
ratePerPeriod = r/INTEREST_CALCS_PER_YEAR

Dim payPeriods as Integer
payPeriods = t * PAYMENTS_PER_YEAR

Dim annualRate as Double
annualRate = Math.Exp(INTEREST_CALCS_PER_YEAR *
Math.Log(1+ratePerPeriod)) - 1

Dim intPerPayment as Double
intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1 *
payPeriods

'Now compute the total cost of the loan
Dim intPerMonth as Double = intPerPayment / PAYMENTS_PER_YEAR

Dim costPerMonth as Double
costPerMonth = P * intPerMonth/(1-Math.Pow(intPerMonth+1,-payPeriods))

'Now display the results in the results Label Web Control
results.Text = "Your mortgage payment per month is $" & costPerMonth
End SubI tried your posted code after adding the 3 necessary textboxes, one label and one button - -

The only problem I could find is line 26:
intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1 * payPeriods
should be:
intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1) * payPeriods

(notice the parenthesis after the -1)

Then, it worked fine for me
Do you have a specific error?

I suggest getting the ASP.NET Unleashed by SAMS
and if you are using VB then the Programming Microsoft Visual Basic .NET by Francesco Balena.

Both of these are ausome books.

Be careful, there are a lot of useless books out there.
ok i added that )
but the error i keep getting is here.

Line 23:
Line 24: Dim annualRate as Double
Line 25: annualRate = Math.Exp(INTEREST_CALCS_PER_YEAR *
Line 26: Math.Log(1+ratePerPeriod)) -1
Line 27:

LINE 25....

i even added the ) mark after the -1, and it still gave me an error.
The error says: Compiler Error Message: BC30201: Expression expected

but in my case, i will gaurentee, that if i get this one fixed, i will get another. :) it has been happening since i started this project...lol
Here is the detailed complier output:

Microsoft (R) Visual Basic .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322.2032
Copyright (C) Microsoft Corporation 1987-2002. All rights reserved.

C:\Documents and Settings\Administrator\My Documents\FinancialCalculator.aspx(25) : error BC30201: Expression expected.

annualRate = Math.Exp(INTEREST_CALCS_PER_YEAR *
~
C:\Documents and Settings\Administrator\My Documents\FinancialCalculator.aspx(26) : error BC30205: End of statement expected.

Math.Log(1+ratePerPeriod)) -1)
~~~~~
C:\Documents and Settings\Administrator\My Documents\FinancialCalculator.aspx(29) : error BC30201: Expression expected.

intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1) *
~
C:\Documents and Settings\Administrator\My Documents\FinancialCalculator.aspx(30) : error BC30454: Expression is not a method.

payPeriods
~~~~~~~~~~
If your code shown here is exactly what you see in your editor then you need to add underscores ( _ ) at the end of each line before hitting "return" to break up the line of code. currently, the processor thinks that what you have is 2 different lines of code. I fear I'm not saying this well...better to show you...

Line 25: annualRate = Math.Exp(INTEREST_CALCS_PER_YEAR * _
Line 26: Math.Log(1+ratePerPeriod)) -1

You may also want to check the rest of your code

Dim intPerPayment as Double
intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1 * _
payPeriods

Try not to lose your patience...remember, errors are a newbie's friend. They will make you stronger and smarter. :) I know, I'm a newbie.
Thank you. that worked. it gave me one more error, but i placed the ) mark after the -1.

so it looked like:

Dim intPerPayment as Double

intPerPayment = (Math.Exp(Math.Log(annualRate+1)/payPeriods) -1) * _

payPeriods

This books so far sahid nothing about the underscore after the lines to seperate them. Again i thank you. This put a smile on my face for the day.
Sorry I missed that - - I did see the continuation of the line and corrected it on my end, but I just thought that's the way it copied to my system - - didn't think it was the actual way it was in the section I copied....I've run into that several times, on the web, and just didn't think twice about fixing the line automatically
Ahh the underscore...
I've run across quite a few books that just wrap the line of code in their examples. So if you were just copying the code directly from the book you would end up with errors. Just be on the look out for things like that.

0 comments:

Post a Comment