| Home | ASP/VBScript | HTML Resources | Graphics |
|
Active Server Pages
|
Ready, Set...Go!
First of all, you will need a server to run your ASP scripts. If you are running Windows 98, the Personal Web Server is included on the CD. If you're not sure if you have installed PWS, check in Control Panel -> Add & Remove Programs -> Windows Setup -> Internet Tools. If The box next to Personal Web Server is checked, you're in business! If not, click on the box, and click OK. Be sure to have your Windows 98 CD handy, as you'll probably need it to complete the install process. If you are running Windows 95 or NT 4, download NT Option Pack 4, which is free to download and use. Win95 users: don't let the name fool you - you'll have the option of specifying Win95 during the download process. Once its downloaded (its a BIG file!), install it following the directions provided by the install routine - its a painless process. Your First Script
Open up a text editor - Notepad or any other plain text editor will do. A text-based HTML editor will also work (I do most of my scripting with Homesite). We'll start out with a very simple script... a take-off on the old "Hello World" script. We'll begin by writing a bit of standard html. This sets up the html page
that the script will write to. Then, we'll put in a bit of vbscript, which is
enclosed by Let's analyse the script portion briefly. First you see the Dim
statement. While it is generally considered good form to declare your variable names
with a Dim statement, it isn't required. Now that I have declared my variable, I next
give it a value. Date() returns today's date.
Next, I want the script to write to the page, so I use response.write in the next three lines. The first two lines of
the response writes text to the screen - when doing this, always remember to enclose
the text string in double quotes. You'll note that I've included an HTML tag in the
response just as long as its within the double quotes. The third response line
returns the value of Today. Note that since VBScript is not case sensitive, I can
get away with capitalizing "response.write" differently in all three lines.
The next line, the one that begins with a single quote, is a comment. Comments
are extremely handy - adding comments to your scripts not only helps you remember
exactly what you were trying to accomplish with a particular part of the script, but
also helps others who see your script to understand your logic.
The final line ends the response. If you have no further scripting on the page,
you can omit this. I use the response.end statement generally when I'm using a conditional
statement (if then...else) and want to go no further if certain conditions are met.
Running Your Script
You must also properly configure the directory in which you save your ASP scripts.
The directory must allow scripts access, and generally its a good idea to turn off read
access in that directory for security reasons. To check this, fire up your web server
administration screen and right-click on your scripts directory.
Now its time to see your script in action. Run your favorite browser, and point
it to http://localhost/script_directory_name/script_name.asp, where script_directory_name is the
actual name of the directory containing your script and script_name.asp is the name
of your script. Now you should see your first effort come to life. Congratulations -
you have just run your first script!
Setting Up a DSN
Setting up the DSN is a simple process. Simply double-click the ODBC applet
in the Control Panel, choose the System DSN tab, and click Add. Choose the type
of database you'll be working with - the sample database from this site is
MS Access - then click finish. You'll then need to type in the database name
in the Data Source Name box, and click Select. Next you'll navigate to the drive
and directory where the database is located, click on the file name and click OK
on that window and the one behind it. Now you can refer to the database by name
in your scripts and the system will know which ODBC driver to use and where the
database is located.
Neat, But...What Now?
Interested in learning more? See the Script Samples and ASP Links and Resources
pages for sample scripts, sites, documentation, tutorials and classes. If you're looking for good
books on ASP, I recommend
Beginning Active Server Pages 2.0
and the "bible" of ASP programming -
Professional Active Server Pages 2.0,
both published by Wrox Press.
|