CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > visual_studio.visual_web_developer_2005_express Tags:
Item Type: NewsGroup Date Entered: 5/17/2007 1:14:59 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 2 Views: 9 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
3 Items, 1 Pages 1 |< << Go >> >|
Welshsteve
Asp.Net User
Problem displaying results of a calculation in a label web control5/17/2007 1:14:59 PM

0/0

I?m not sure if anyone can help, but I'm trying to use a feature covered in the SAMS Publishing ?ASP.NET 2.0 in 24 Hours? book.

I?m trying to use the Financial Calculator outlined in the book for a website I?m building. I have got the calculator to work by following the steps in the book.  Here's the code for it.

FinancialCalculator.aspx

1    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="FinancialCalculator.aspx.vb" Inherits="FinancialCalculator" %>
2    
3    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4    
5    <html xmlns="http://www.w3.org/1999/xhtml" >
6    <head runat="server">
7        <title>Untitled Page</title>
8    </head>
9    <body>
10       <form id="form1" runat="server">
11       <div>
12           Amount: <asp:TextBox ID="loanAmount" runat="server"></asp:TextBox><br />
13           Interest Rate:
14           <asp:TextBox ID="rate" runat="server"></asp:TextBox><br />
15           Term:
16           <asp:TextBox ID="mortgageLength" runat="server"></asp:TextBox><br />
17           <br />
18           <asp:Button ID="performCalc" runat="server" Text="Compute Monthly Cost" /><br />
19            <br />
20           <asp:Label ID="results" runat="server"></asp:Label></div>
21       </form>
22   </body>
23   </html>
  

FinancialCalculator.aspx.vb

1   
2    Partial Class FinancialCalculator
3        Inherits System.Web.UI.Page
4   
5        Protected Sub performCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles performCalc.Click
6            Const INTEREST_CALCS_PER_YEAR As Integer = 12
7            Const PAYMENTS_PER_YEAR As Integer = 12
8   
9            Dim P As Double = loanAmount.Text
10           Dim r As Double = rate.Text / 100
11           Dim t As Double = mortgageLength.Text
12  
13           Dim ratePerPeriod As Double
14           ratePerPeriod = r / INTEREST_CALCS_PER_YEAR
15  
16           Dim payPeriods As Integer
17           payPeriods = t * PAYMENTS_PER_YEAR
18  
19           Dim annualRate As Double
20           annualRate = Math.Exp(INTEREST_CALCS_PER_YEAR * Math.Log(1 + ratePerPeriod)) - 1
21  
22           Dim intPerPayment As Double
23           intPerPayment = (Math.Exp(Math.Log(annualRate + 1) / payPeriods) - 1) * payPeriods
24  
25           Dim intPerMonth As Double = intPerPayment / PAYMENTS_PER_YEAR
26  
27           Dim costPerMonth As Double
28           costPerMonth = P * intPerMonth / (1 - Math.Pow(intPerMonth + 1, -payPeriods))
29  
30           results.Text = "Your monthly repayments will be ?" & costPerMonth
31  
32       End Sub
33   End Class

34  


But when trying to use it in the website I?m building, it won?t work. This website I?m building uses a master page.

Here is my code for these pages.

MasterPage.master

1    <%@ Master Language="VB" %>
2    
3    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4    
5    <script runat="server">
6    
7    </script>
8    
9    <html xmlns="http://www.w3.org/1999/xhtml" >
10   <head id="Head1" runat="server">
11       <title>The Gateway Calculators Suite</title>
12       <link rel="stylesheet" type="text/css" href="styles_generic.css" />
13   </head>
14   <body>
15       <form id="form1" runat="server">
16           <!-- START HEADER -->
17           <div id="header">
18           </div>
19           <!-- END HEADER -->
20   
21           <!-- CONTENT CONTAINER -->
22           <div id="wrapper">
23   
24               <!-- NAVIGATION -->
25               <div class="leftMenu">
26                       <h2>Welcome</h2>
27                       <a class="menuLeft" href="Default.aspx">Calculators Home</a>
28                       <a class="menuLeft" href="http://www.gatewayconsortium.com" target="_blank">Gateway Portal</a>
29                       <h2>Calculators</h2>
30                       <a class="menuLeft" href="Overture.aspx">Overture</a>
31                       <a class="menuLeft" href="Foundation.aspx">Foundation</a>
32                       <a class="menuLeft" href="DirRemun.aspx">Directors Remuneration</a>
33                       <a class="menuLeft" href="ComLoans.aspx">Commercial Loans</a>
34                       <a class="menuLeft" href="ComProp.aspx">Commercial Property</a>
35                       <a class="menuLeft" href="Graph.aspx">Graph Generator</a>
36                       <a class="menuLeft" href="Compound.aspx">Compound Interest</a>
37               </div>
38               <!-- END NAVIGATION -->
39               
40               <!-- CONTENT -->
41               <asp:contentplaceholder id="ContentPlaceHolder1" runat="server">
42    
43               </asp:contentplaceholder>
44   
45           </div> 
46           <!-- END CONTAINER -->
47   
48           <!-- FOOTER -->
49           <div id="footer">
50                   <p style="display:inline;float:left;"> ?Copyright 2007 - The Gateway Consortium Limited - All rights reserved</p>
51                   <p style="display:inline;float:right;margin-right:5px;">Developed by Steve Williams</p>
52           </div>
53           <!-- END FOOTER -->
54       </form>
55   </body>
56   </html>
57   


ComLoans.aspx

1    <%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="ComLoans.aspx.vb" Inherits="ComLoans" title="The Gateway Calculators - Commercial Loans" %>
2    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
3        <div class="content">
4            <h1>Commercial Loans</h1>
5            <table>
6                <tr>
7                    <td>Amount to borrow:</td>
8                    <td style="width:20px;text-align: right;">?</td>
9                    <td><asp:TextBox ID="txtAmount" runat="server" BackColor="#FFF6C3" BorderColor="Navy" BorderStyle="Solid" BorderWidth="1px"></asp:TextBox></td>
10               </tr>
11               <tr>
12                   <td>Interest Rate:</td>
13                   <td style="width:20px;text-align: right;"> </td>
14                   <td><asp:TextBox ID="txtRate" runat="server" BackColor="#FFF6C3" BorderColor="Navy" BorderStyle="Solid" BorderWidth="1px"></asp:TextBox>%</td>
15               </tr>
16               <tr>
17                   <td>Term:</td>
18                   <td style="width:20px;text-align: right;"> </td>
19                   <td><asp:TextBox ID="txtTerm" runat="server" BackColor="#FFF6C3" BorderColor="Navy" BorderStyle="Solid" BorderWidth="1px"></asp:TextBox> years</td>
20               </tr>
21               <tr><td colspan="3"> </td></tr>
22               <tr>
23                   <td colspan="3">
24                       <asp:Button ID="btnCalc" runat="server" Text="Calculate Monthly Repayments" />
25                       <input id="Reset" type="reset" value="Reset Form" />
26                   </td>
27               </tr>
28               <tr><td colspan="3"> </td></tr>
29               <tr>
30                   <td>Monthly Cost:</td>
31                   <td style="width:20px;text-align: right;">?</td>
32                   <td><asp:Label ID="lblRepay" runat="server" Text=""></asp:Label>
33               </tr>
34           </table>
35         
36       </div>
37   </asp:Content>
38   
39   

ComLoans.aspx.vb

1    
2    Partial Class ComLoans
3        Inherits System.Web.UI.Page
4    
5        Protected Sub btnCalc_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCalc.Click
6            'Specify constant values
7            Const INTEREST_CALCS_PER_YEAR As Integer = 12
8            Const PAYMENTS_PER_YEAR As Integer = 12
9    
10           'Create variable to hold the values entered in text boxes
11           Dim P As Double = txtAmount.Text
12           Dim r As Double = txtRate.Text / 100
13           Dim t As Double = txtTerm.Text
14   
15           Dim ratePerPeriod As Double
16           ratePerPeriod = r / INTEREST_CALCS_PER_YEAR
17   
18           Dim payPeriods As Integer
19           payPeriods = t * PAYMENTS_PER_YEAR
20   
21           Dim annualRate As Double
22           annualRate = Math.Exp(INTEREST_CALCS_PER_YEAR * Math.Log(1 + ratePerPeriod)) - 1
23   
24           Dim intPerPayment As Double
25           intPerPayment = (Math.Exp(Math.Log(annualRate + 1) / payPeriods) - 1) * payPeriods
26   
27           'Work out total cost of the loan
28           Dim intPerMonth As Double = intPerPayment / PAYMENTS_PER_YEAR
29   
30           Dim costPerMonth As Double
31           costPerMonth = P * intPerMonth / (1 - Math.Pow(intPerMonth + 1, -payPeriods))
32   
33           'Display result in the label control
34           lblRepay = costPerMonth
35   
36       End Sub
37   End Class
38   
 

The error I am getting is:

Compiler Error Message: BC30311: Value of type 'Double' cannot be converted to 'System.Web.UI.WebControls.Label'.


Error Screenshot

.. which is related to me trying to display the result in a label web control when the user submits it. I don't understand why this is happening upon loading the page, because this event shouldn't occur until the user clicks the button.

I am using Microsoft's Visual Web Developer Express 2005 to build this site.

I have attached the code rather than post it in code boxes here because there is a lot of it.

Benson Yu - MSF
Asp.Net User
Re: Problem displaying results of a calculation in a label web control5/18/2007 6:38:55 AM

0/0

Hi Welshsteve,

Based on the error message, I understand you view the page by right click the ComLoans.aspx in ?Solution Explorer? and select ?View in Browser?.

The error is a compile time error. The Compiler detects the error and throws the error to prevent the page to run. The correct code should be: lblRepay.Text = costPerMonth

Only the runtime error will occur when executing the code. For example:
lblRepay.Text = Convert.ToDateTime(costPerMonth).ToString()


 


Sincerely,
Benson Yu
Microsoft Online Community Support

Please remember to click ?Mark as Answer? on the post that helps you, and to click ?Unmark as Answer? if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Welshsteve
Asp.Net User
Re: Problem displaying results of a calculation in a label web control5/18/2007 8:40:10 AM

0/0

Oops, should have spotted that.  Many thanks for that. :)

I also added the below code because the result was giving the answer in about 8 decimal places.Smile

costPerMonth = Math.Round(costPerMonth, 2)

3 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Mastering Visual Basic.NET Authors: Evangelos Petroutsos, Pages: 1153, Published: 2002
Object-Oriented ActionScript 3.0 Authors: Peter Elst, Sas Jacobs, Todd Yard, Pages: 615, Published: 2007
Beginning SQL Server 2005 Express Database Applications: With Visual Basic Express and Visual Web Developer Express from Novice to Professional Authors: Rick Dobson, Pages: 596, Published: 2005
.Net Test Automation Recipes: A Problem-solution Approach Authors: James D. McCaffrey, Pages: 380, Published: 2006
Special Edition Using Visual Basic.NET Authors: Brian Siler, Jeff Spotts, Pages: 848, Published: 2001
XForms Essentials Authors: Micah Dubinko, Pages: 232, Published: 2003
Foundation Flex for Developers: Data-Driven Applications with PHP, ASP. Net, Coldfusion, and LCDs Authors: Sas Jacobs, Koen de Weggheleire, Pages: 545, Published: 2007
The Software Catalog: Microcomputers, Winter, 1990 Authors: Menu International Software, Pages: 0, Published: 1990
Encyclopedia of Law Enforcement Authors: Larry E. Sullivan, Marie Simonetti Rosen, Sage eReference (Online service, Dorothy Moses Schulz, inc Sage Publications, Maria R. Haberfeld, Pages: 0, Published: 2005

Web:
4GuysFromRolla.com - Teach Yourself ASP.NET in 24 Hours Complete ... In order to display the output of our calculation, we need to add a Label Web control to our ASP.NET page. This Label Web control will display the result of ...
Moving from Visual Basic to ASP.NET The first one is a Label Web control that will display the results of the financial calculation. Place this Label Web control near the bottom of the page; ...
Safari Books Online - 0672327384 - Sams Teach Yourself ASP.NET 2.0 ... Displaying text using the Literal and Label Web controls ... wanted the result; and a Label Web control, where the output of the calculation was displayed. ...
CodeProject: Age Calucate Web Custom Control. Free source code and ... May 20, 2008 ... Age Calculation Web Custom Control [AgeCalWCC] ' ' This AgeCalWCC is developed by .... 'Label control for displaying the result lblResult. ...
CR XI - Shipping Labels Report - Qty Calculation/Display Options ... Add the control table to your report but do NOT link it to your other table(s). ... 1 ) so you'll get a result of 10 in your example and produce 10 labels. ...
Peter's Interactive Pages - PeterBlum.com It can display the result of the calculation in a label or another textbox. ... feature rich and interactive data entry web forms with over 70 web controls. ...
ASP.NET Mobile Controls The second form needs only a label to display the results and a link so a ... make a new calculation; Exercise 4: Adding Event Logic to Make the XML Web ...
ASP.NET Tutorials - Lesson 6: Using Forms This is mostly done by displaying web controls to the user who can click them, ... or you can process them in a calculation or a similar operation. ...
TestformsSyn versions Labels control key pad modified so that keys 1 to 9 specify the number of .... MSU results etc display 'Double click to display result' rather than the ...
Convert Excel calculations to literal values : TechGuides ... Oct 16, 2008 ... Avoid problems by using Paste Special to copy values rather than formulas. ... Click in the text box control label and type Web Address: ...




Search This Site:










no protecteddata class

connection issues with login control / web configuration tool

modulehelp.text localization using cdata

solution partners menu module private assembly

debug error

how do i use internal iis instead of built in server

unable to authenticate

upgrade question

1 main hor menu and 1 vert child menu.

store user info into session

missing script.sql

dotnetnuke file manager upload is not longer working

querystring username and password

how to re use authenticated user name and password of sharepoint site in networkcredential() method as parameters

users table

will vs.net 2005 include objectspaces

windows authentication/authorization: how to allow only one type of group/role to enter website?

logo's...(multiple)

error - user does not have permission to perform this action.

dnn 3.0.7 bug - a certain combination of modules causes errors

problems creating a personal design time layout for my control

vbcrlf does not start a new line in asp.net 2.0.

control designer vs. tree structure of child controls

dynamically add text value to linkbutton in skin file

module title as image

credential prompt ??

="general_exception"

sqldatetime overflow. need help on how to use getnull()

design view in vs.net 2003

dynamic treeview control

 
All Times Are GMT