Saturday, March 31, 2012

Where do I place Imports System.Math

I have this code

===================
Imports System.Math

Sub btnCalculate_Click(sender As Object, e As EventArgs)

Dim LoanPayment as Single

'Use Pmt function to determine payment for 36 month loan

LoanPayment = Pmt(txtInterest.text / 12, 36, txtAmount.text)

txtPayment.text = Format(Abs(LoanPayment), "$0.00")

End Sub
===================

But when I run it I get the following Err Msg

===================
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30465: 'Imports' statements must precede any declarations.

Source Error:

Line 2: <script runat="server">
Line 3:
Line 4: Imports System.Math
Line 5:
Line 6:
===================
In the All Tab I have

<%@dotnet.itags.org. Page Language="VB" %>
<script runat="server"
Imports System.Math

Sub btnCalculate_Click(sender As Object, e As EventArgs)

Dim LoanPayment as Single

'Use Pmt function to determine payment for 36 month loan

LoanPayment = Pmt(txtInterest.text / 12, 36, txtAmount.text)

txtPayment.text = Format(Abs(LoanPayment), "$0.00")

End Sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<font size="5">Car Loan Calculator</font>
</p>
<p>
Enter the required information and clickCalculate!
</p>
<p>
<asp:TextBox id="txtAmount" runat="server"></asp:TextBox>
<asp:Label id="Label1" runat="server">Loan Amount</asp:Label>
</p>
<p>
<asp:TextBox id="txtInterest" runat="server"></asp:TextBox>
<asp:Label id="Label2" runat="server">Interest Rate</asp:Label>
</p>
<p>
<asp:TextBox id="txtPayment" runat="server"></asp:TextBox>
<asp:Label id="Label3" runat="server">Monthly Payment</asp:Label>
</p>
<p>
<asp:Button id="btnCalculate" onclick="btnCalculate_Click" runat="server" Text="Calculate"></asp:Button>
</p>
<!-- Insert content here -->
</form>
</body>
</html>
===================

I tried moving the Imports System.Math to the top but then I get a msg that the abs is not recognize<%@.Import Namespace="System.Math"%>
Thank You! Now it works ;-)

0 comments:

Post a Comment