none
‘variable’ is not declared. It may be inaccessible due to its protection level.

    Question

  • USER::  Name: Gary Schideman

                  Email:  gschideman@verizon.net

    QUESTION:  What Visual Basic coding changes are required to enable the aspx.vb recognition

                         of the 3 aspx input texts in the below sample program?    [Execution is enabled by

                         hard coding the 3 input texts in FinancialCalculator.aspx.vb.]

    SOFTWARE:  Visual Web Developer 2010 Express

                            Asp.Net      

                            Windows 7 Home Premium

                            Internet Explorer  9

    Documentation:  Sams Teach Yourself  ASP.NET  2.0  in 24 Hours  by  Scott Mitchell

    Debugging Errors:

                  ‘loanAmount’ is not declared.  It may be inaccessible due to its protection level. 

                  ‘intRate’ is not declared.  It may be inaccessible due to its protection level. 

                 ‘mortgageLength’ is not declared.  It may be inaccessible due to its protection level. 

    FINANCIAL CALCULATOR

    [Execution is enabled by hard coding the 3 input texts in FinancialCalculator.aspx.vb.]

    Principal Amount:<input name="loanAmount" value="250000" />

    Annual Interest Rate: <input name="intRate" value="6.0" />%

    Mortgage Length: <input name="mortgageLength" value="30" />years

    <input action="FinancialCalculator.aspx" method="post" name="ctl00$MainContent$performCalc" type="submit" value="Compute Monthly Cost" />

    Your mortgage payment per month is $1496.55413199553

                    


    FinancialCalculator.aspx.vb

    Partial Class _Default

        Inherits System.Web.UI.Page

        Protected Sub performCalc_Click(sender As Object, e As System.EventArgs) Handles performCalc.Click

            'Specify constant values

            Const INTEREST_CALCS_PER_YEAR As Integer = 12

            Const PAYMENTS_PER_YEAR As Integer = 12

            'Create variables to hold the values enter

            Dim P As Double = loanAmount.Text

            Dim r As Double = intRate.Text / 100

            Dim t As Double = mortgageLength.Text

            'Visual Basic errors indicate that above 3 input text box names are not declared.

            Dim P As Double = 250000

            Dim r As Double = 0.06

            Dim t As Double = 30

            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

    End Class


    FinancialCalculator.aspx

    <%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="false"

        CodeFile="FinancialCalculator.aspx.vb" Inherits="_Default" %>

    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">

    </asp:Content>

    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">

        <h2>

            FINANCIAL  CALCULATOR

        </h2>

        <p>

           

            <strong>Principal Amount:</strong>

            <input id="loanAmount" type="text" name="loanAmount" /></p>

        <p>

           

            <strong>Annual Interest Rate: </strong>

            <input id="intRate" type="text" name="intRate" /><strong>%</strong></p>

        <p>

           

            <strong>Mortgage Length</strong>:

            <input id="mortgageLength" type="text" name="mortgageLength" /><strong>years</strong></p>

        <p>

           

            &nbsp;</p>

        <p>

           

            <asp:Button ID="performCalc" runat="server" Text="Compute Monthly Cost" />

           

        </p>

        <p>

           

            <asp:Label ID="results" runat="server"></asp:Label>

           

        </p>

        <p>

           

        </p>

    </asp:Content>

    Saturday, July 21, 2012 1:35 AM

All replies

  • Hi gschideman,

    Thank you for posting in the MSDN forum.

    Based on your description, this issue is related to ASP.Net. You could post this issue in http://forums.asp.net where asp.net experts live in. Thanks for your understanding.

    Thanks,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, July 24, 2012 5:10 AM