Professor Chris Sandvig MBA 597 - Introduction to Web Development Management Spring 2005

Last updated: 10/22/2003 9:41:21 AM

<% if printFile < " " then response.write("
") end if %>

Assignment 4 - VBScript Variables

You may find it useful to have your copy of M&A available as a reference while you work on your labs.  The information needed to complete this assignment is covered in M&A chapters 2, 3 and 4.

You will create many files during the class so it would be a good idea to organize them by assignment. A good directory name for this assignment would be A04.

1. ClockLoop.asp  Add a For Next loop to the code shown in class so that the clock (and heading) repeat 10 times. 

The following questons require the use of simple HTML form. Below is the code.

<center>

<form>
    <p>Please enter your name: 
    <input type="text" name="FirstName">
    <input type="submit" value="Submit Name"></p>
</form>

<% If request("FirstName") > "" then
       response.write "<h1>Hello " & request("FirstName")
   end if
%>

 

2. HelloForm.asp - Use Aspen to paste the code above into a file on and name it HelloForm.asp.

3. GuessGame.asp - Use an if statement similar to the one in greeting example to give the user hints as they try to guess a number: 

Value entered Hint
<4 Way too low
4-6 Low
7 Correct!
8-10 High
> 10 Way too high

4. AgeCalculator.asp - Write a script that calculates a person's age in years, months and days. Use the dateDiff function to calculate the difference between the current date and the user's birthday. The syntax for displaying the difference in years is: 

dateDiff("yyyy", request("strBirthDate"), date()). 

Read the DateDiff documentation to see how to display age in the three formats (years, months and days).

5. CookieTally.asp - It is easy to read and write cookies in ASP. The syntax to write a cookie named "myCookie" with a single key named "Tally" and a value of 4 is:

 response.cookies("myCookie")("Tally") = 4.

To read the same cookie the syntax is: request.cookies("myCookie")("Tally").  

Write a script that uses a cookie to keeps a running tally of the values entered by a user. 

Tip 1: All data retrieved from HTML forms is of type "string."  Before you try to perform an addition operation you will need to convert the string to type double floating point (otherwise VBScript will concatenate the strings rather than add the values).  Use the VBScript function CDbl (documentation & examples) to convert user inputs from type string to type double floating point as follows:

dblInput = CDbl(request("strInput"))

Cookies also store data in a string format. You will need to convert the data retrieved from the cookie to a numerical format before attempting the addition::

dblCookie = Cdbl(request.cookies("MyCookie")("Tally"))

Tip 2: To see the contents of the cookie created by the example click here.

Tip 3: If you would like to see your cookie in the folder C:\Documents and Settings\Your Name\Cookies you will need to give it an expiration date. The syntax for setting a cookie's expiration date is:

response.cookies("myCookie").expires = date() + 30

This will give the cookie named "myCookie" an expiration date of 30 days from the day it was last written.

 


Submitting your assignment via email:

  1. The subject line of your email should read "MBA597 Ax YourName" where x is the assignment number.

  2. Send to .

  3. cc a copy to yourself (as a time-stamped receipt of your submission).
     
    Please check your URLs for accuracy since incorrect addresses will not be graded.