ASP Calculator using a form with the POST method

This calculator uses ASP technology. ASP pages contain VBscripts that run on the server, not the client, so the numbers input here cannot be processed by the client computer (which has received no script) - instead the data is posted to another page - actually this same page, which opens a second time. As the second version of the page is prepared by the ASP script the necessary calculations are performed and included in the page that is sent. 

In this particular case it would obviously be more efficient to have a script on the client computer to do the calculations. This page, although demonstrating that an ASP page may be made to appear interactive, above all highlights the limitations of ASP technology. Nevertheless, ASP makes possible many functions that cannot be achieved with client-side scripts as well as offering other advantages such as the invisibility of server-side scripts and the possibility of writing scripts in VBscript knowing there will be no incompatibility with client computers running Netscape Navigator.

/      

The code for this page, including the ASP script, is below. It includes code to check that the contents of each text box can be converted to a number, the actual conversion (without which the 'addition' actually becomes a concatenation like 2+3=23) and a test for division by zero. This page uses the POST method to send the data to another page (which happens to be the same page). The GET method can also be used and is demonstrated HERE - it has the disadvantage that the data appears in the URL address line at the top of the screen.

<%
if isnumeric (Request.form ("x")) and isnumeric (Request.form ("y")) then
    x = cdbl (Request.form ("x")) 'convert to number (double precision type)
    y = cdbl (Request.form ("y"))
    select case Request.Form("operator")
    case "add"
        msg = x & "+" & y & "=" & x+y
    case "subtract"
        msg = x & "-" & y & "=" & x-y
    case "multiply"
        msg = x & "*" & y & "=" & x*y
    case "divide"
        if y = 0 then
            msg = "division by zero!"
        else
            msg = x & "/" & y & "=" & x/y
        end if
    end select
else
    msg = "enter numbers:"
end if
response.write "<b>" & msg & "</b>"
%>
<form method="POST" action="calculator.asp">
<p>
<input type="text" name="x" size="14">
<input type="radio" name="operator" value="add">+&nbsp;
<input type="radio" name="operator" value="subtract">-&nbsp;
<input type="radio" name="operator" value="multiply">*&nbsp;
<input type="radio" name="operator" value="divide">/&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="y" size="20">
<input type="submit" value="Submit" name="process">&nbsp;
</p>
</form>