I'm reading the Sams "Teach Yourself ASP.NET in 24 hours" book, and I like it a lot. But when I tried Chapter 3's "Creating Our First ASP.NET Web Page" financial caluclator (see complete code below), I didn't get any response after testing it out.
So I then went to the Sams Publishing website at http://www.samspublishing.com/articles/article.asp?p=32471&seqNum=3 to directly copy & paste the referenced script into the page. When I refreshed the page, and tried the calculator again, I still did not receive any result on the Label. If anyone can review the code included below, and let me know if and how I'm doing something wrong, it would be greatly appreciated. Thanks!
<%@ Page Language="VB" Debug="true" %>
<script runat="server">
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 Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
</p>
<p>
Mortgage Amount:
<asp:TextBox id="loanamount" runat="server"></asp:TextBox>
</p>
<p>
Annual Interest Rate:
<asp:TextBox id="rate" runat="server"></asp:TextBox>
</p>
<p>
Mortgage Length:
<asp:TextBox id="mortgageLength" runat="server"></asp:TextBox>
</p>
<p>
<asp:Button id="performCalc" runat="server" Text="Compute Monthly Cost"></asp:Button>
</p>
<p>
<asp:Label id="results" runat="server"></asp:Label>
</p>
<!--Insert web controls here -->
</form>
</body>
</html>