How to use <Script Language =VBScript >

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lenniekuah
    New Member
    • Oct 2006
    • 126

    #1

    How to use <Script Language =VBScript >

    Hi Helpful Good Guys,

    I need your help. Please help me.

    I have been asked to transfer the FUNCTION FCalculate from WebFrmLoan.aspx to Web Page CODEBEHIND. The Functon event is to calculate the Loan Monthly Repayment amount.


    I have not done it before using VBScript and it generated this error message.

    Option Strict On requires all Function, Property, and Operator declarations to have an 'As' clause.

    This is the coding that generate the error message:
    Code:
    <script language= "vbscript" runat=server>               
            Protected Function FCalculate(ByVal Sender As Object, ByVal e As EventArgs)
                Dim intPaym As Double = 0
                intPaym = (CType(Me.txtLoanAmt.Text, Double) / CType(Me.txtTotalMonth.Text, Long))
            End Function
        </script>
    --------------------------------
    Here are the overall coding from WEB PAGE CODEBEHIND:
    Code:
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebFrmClientSideScript.aspx.vb" Inherits="ASPNET2008DataEntry.WebFrmClientSideScript" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Loan Repayment Page</title>
        <link href="StyleSheet1.css" rel="stylesheet" type="text/css" />
        <style type="text/css">
            .style1
            {
                width: 547px;
            }
        </style>
    </head>
    <!-- -------------------------------------------------------------------- -->
        <script language= "vbscript"  runat= server>
                   
            Protected Function FCalculate(ByVal Sender As Object, ByVal e As EventArgs)
                Dim intPaym As Double = 0
                intPaym = (CType(Me.txtLoanAmt.Text, Double) / CType(Me.txtTotalMonth.Text, Long))
            End Function
        </script>  
    <!-- -------------------------------------------------------------------- -->
    <body>
        <form id="form1" runat="server">
        <div class="LeftMargin">
            <asp:Label ID="lbl1" CssClass="labelBanner" runat="server"
                     Text="Loan Monthly Repayment Calculation" >
            </asp:Label>                 
        </div>        
        <br />
        
        <div class="LeftMargin">
            <table style="width:100%;"
                    <tr>
                        <td align="left" class="style1">
                            <asp:Label ID="lbl2" CssClass="labelText" runat="server" Width="300px" 
                                     Text="Loan Amount $:" ></asp:Label>
                            <asp:TextBox ID="txtLoanAmt" CssClass="textbox" runat="server"
                                       EnableViewState="true" AutoPostBack="false" TabIndex="1"></asp:TextBox>                        
                        </td> 
                     </tr>
                     
                     &nbsp;
                     <tr>
                        <td class="style1">
                            <asp:Label ID="lbl3" CssClass="labelText" runat="server" Width="300px"
                                     Text="Repayment Months Count :"></asp:Label>
                            <asp:TextBox ID="txtTotalMonth" CssClass="textbox" runat="server"
                                      EnableViewState="true" AutoPostBack="false" TabIndex="2"></asp:TextBox>                                     
                        </td>                  
                        &nbsp;
                        <td>
                            <asp:Label ID="lbl4" CssClass="labelText" runat="server" Width="400px"
                                     Text="Monthly Repayment Amount :"></asp:Label>
                            <asp:TextBox ID="txtPayAmt" CssClass="textbox" runat="server"
                                     EnableViewState="true" AutoPostBack="false" TabIndex="3"
                                      Enabled="false" ></asp:TextBox>
                         
                        </td>
                     </tr> 
                 
               
                     <tr class="LeftMargin">
                        <td>
                            <asp:Label ID="lbl5" runat="server" Width="200px"></asp:Label>
                            <asp:Button ID="BtnCalculate" CssClass="Button" runat="server"
                                     Text="Monthly Payment Calculate" OnClick="FCalculate"
                                      Width="200px" />                             
                        </td>
                     </tr>
            
            </table>      
        </div>
        
        </form>
    </body>
    </html>
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Fistly, VBScript is not a .NET language as far as I know. VBScript is used for classic asp development (not ASP.NET).

    You have posted VB.NET code...however a Function returns something to the calling code, whereas a Sub does not return anything. Since your method does not return anything to the calling code, change the Function into a Sub. Also, consider using the "Handles" keyword to handle events for controls.

    -Frinny

    Comment

    • lenniekuah
      New Member
      • Oct 2006
      • 126

      #3
      Hi Frinavale,
      Thank you for your additional information
      .

      Due to my lack of experences and knowledge can you please make changes to my posted coding using HANDLES ? That would give me the opportunity to understand it logically.

      Thank you for your help.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Well it's all in the method signature.
        If you have a button called "btn_FCalculate " and you want to handle the button click event for this button. You would implement a method that Handles that event:

        Code:
        Protected Sub btn_FCalculate(ByVal Sender As Object, ByVal e As EventArgs) Handles btn_FCalculate.Click
          '....
        End Sub
        Now when the button is clicked, and the Click event is fired, that method will be executed (it will handle the event) :)

        -Frinny

        Comment

        • lenniekuah
          New Member
          • Oct 2006
          • 126

          #5
          Hi Wonderful Frinavale,
          Thank you for helping me. I have tried out your suggestion and it's working.
          Yaaa....Hooo

          Comment

          Working...