Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic
Learn VB and ASP
Part 2: The ASP Quote Picker
 Join the Discussion
A Visual Basic CASE statement can be a poor man's database. What techniques work for you?
Discussion Forum
 

Let's look at a complete ASP page. The idea is to display a different quote every time someone accesses the page. In most cases, this would probably be done with a database, but if your needs are modest, you can get the same result with a simple VBScript 'CASE' statement.

Note that the script starts the same way that a normal HTML web page would. <HTML>, <HEAD>, <BODY>. So far, everything's pretty normal. Then you get this strange
"<%=date%>"
thingy. That's an ASP statement. The server converts that into the server date and plugs it into the same spot in the HTML.

     <html>
     <head>
     <title>The Quote Picker Page</title>
     </head>
     <body>
     <H2>Your quote for <%=date%>.</H2>
     <%Randomize
     intChoice = int(Rnd * 26)
     Select Case intChoice
     Case 0%>Home is where you hang your '@'
     <%Case 1%>The E-mail of the species ...
     <%Case 2%>A journey of a thousand sites ...
      ... intermediate quotes deleted ...
     <%Case 25%>Give a man a fish ...
     </body>
     </html>

The next paragraph isn't nearly as straightforward. The ASP starts with the "<%" before "Randomize" and continues down to the first quote after "Case 0%>."

Notice that the ASP and the HTML are mixed together. This is a key concept. If you just sent this page to a browser "as is," the browser would ignore the ASP code statements. It would "see" all of the text in the quotes, however, and just string them together and display all of them. But when the server sees that this is an ASP file, it executes the ASP statements first and only one random quote gets sent to the browser as part of the HTML.

ASP is Microsoft's technology for adding programming power to web servers, but you can run it on most web servers anyway. If you run Unix, Linux, Solaris, even OS/390 … companies like Chilisoft (ironically, owned by Microsoft's arch-enemy, Sun) and Stryon supply software that also runs ASP.

In order to run ASP on a single computer, you need either IIS (which comes with Windows 2000 and XP Pro versions) or a free product from Microsoft called PWS (Personal Web Server). You can find specific instructions about PWS on the Microsoft web page here.

Start Page > Take Names and Kick Assets With VB and ASP! > Page 1

Explore Visual Basic

By Category

About.com Special Features

Build Your Own Website

Step-by-step advice on how to do everything from choosing a Web host to promoting your content. More >

Connect Your Home Computers

Easy ways to connect two computers for networking purposes. More >

Visual Basic

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.