ASP   «Prev  Next»

ASP Constants and Variables - Exercise

Run an ASP script


Objective: Observe behavior of a browser interpreting an ASP script.

Scoring

This exercise is an opportunity for you to check your understanding of the material covered in the preceding lesson. When you are finished, click the Submit button to view the suggested results.

Background/overview

This lesson and the previous one presented examples of simple ASP scripts and the results that a visitor to the Web site would see in his/her browser. If you change any of the calculations or values in a script, it should also change the result that the browser displays.
In this exercise, you will copy or re-input and save our sample ASP discount script. Then you will then run it, modify it, and run it again to convince yourself, if you have not worked with server-side scripting before, that the resulting HTML is dynamic. Later lessons will show you how to code the ASP scripts to change the result of a displayed calculation.

Instructions

Copy and paste the HTML/ASP code below (or input it) into your HTML editor and save it as asptest1.asp.

<HTML>
  <TITLE>Constants</TITLE>
  <BODY>
  <% 'BEGIN ASP SCRIPT
	  Dim nTotal 'Initialize a numeric variable
    Const cnDiscount = .10 'Set this numeric constant 'to a value
    nTotal = 20 'Set this numeric variable 'to a value
  %>
<!–END ASP SCRIPT ––>
  Your $<%=nTotal%> total with a 10% 
  discount is $<%=nTotal – (nTotal * cnDiscount)%>!
</results>
</html>
  1. Run the ASP script and observe the result in your browser.
  2. Modify the ASP script to change the total amount from 20 to 60 (that is, change the contents of nTotal) and re-save it.
  3. Re-run the modified ASP script and observe the result in your browser.

Hints

In order for an ASP script to be run, it must reside in a web shared or virtual directory.
You should create a virtual directory under wwwroot and store all non-course project exercises in it.
When viewing the completed script in your browser, be sure to use http://localhost for your path instead of C:\webshare\... This will allow the ASP file to be processed by the web server before it is returned to the client.