Taste ASP's power with starter scripts

Try these scripts to test ASP's power and to build your VBScripting skills.

By Amy Cowen

Like most scripting languages, the best way to learn ASP is to dive right in. ASP is a hands-on technology, and using your own system—with a copy of PWS or IIS installed—you can test ASP commands and functions on your local server as you are learning them. To get you started, we've compiled some handy scripts that give you a taste of ASP's power and flexibility and help build your VBScripting repertoire.

ASP isn't something you can learn by viewing the source code of other sites. In fact, ASP sections of your page are processed before the content is written to the screen. So, if you had this snippet on your page:

<% Response.Write "Your name is" & strName %>
when you view the source of the delivered page, you'll see this (if strName equaled "Jane."):
Your name is Jane
Your pages may contain numerous script sections or may be total script, but what will be visible from a View Source command is the HTML code that was delivered as the output of the .asp page.

Hello World
No tutorial would be complete without a Hello World script. To see ASP in action, copy the code below into a file, name it with a .asp extension, and open it in your browser. (Don't forget to use your local server address/path to call up the page.)

  <TITLE>Hello World Sample</TITLE>
    <% Response.Write "Hello World" %>
The middle section is an ASP script that writes "Hello World" to the screen.

Greeting Your Users
The Hello World sample used information we provided (the phrase Hello World). With the same amount of effort, you can access information, such as date and time, using built-in VBScript functions. For example, you won't pull any muscles putting the current time on every page. Just slot this little code snippet onto your page:

It is now <%= Time %>.
You can choose how you format the appearance of, and context for, time. As long as the ASP section remains intact, the local server time will be written to the screen.

Simple If…Then or Select Case testing could be used to further enhance this example. Or, if you want to think a bit outside of the box, you could use the time as a variable to test against in order to change the background color, font colors, welcome statements, or even to determine which page is shown (using Response.Redirect).

Editor's Picks