To the Reader from Joe: This is a user-submitted tutorial by the author above. I have read the tutorial and
set the format to fit HTML Goodies, but for the most part have not changed the language. I chose this tutorial because
many readers have been asking for more ASP tutorials. This is a great one.
Sorry I cannot show you the event here.
The HTML Goodies servers do not offer ASP. I will tell you though that if you run IE5.0 or better, open the contents
of the zip file into a directory and it runs just fine.
If you haven’t already, you may want to read my introductory ASP tutorial before this one. If not,
then enjoy.
There may be a point in your web design career, where your site becomes real
popular. That is when companies become interested in advertising on your site. A
Banner Ad system can be built to control all those advertisements that you are so
willing to display, for a price. Active Server Pages
makes it very easy to create a banner ad system. So easy, that the Microsoft ASP
developers created an “AdRotator” component for the occasion. Before you begin reading this article,
make sure you download the support material below.
Banner System Zip
All the files you need are right here
The files included are
ad.txt
banner.asp
3 banner images
clicks.asp
example.asp
redirect.asp
ad.txt
In order for the AdRotator component to work, you must configure a text file. This
text file contains all the banner ad properties. However, The text file must follow a certain
format. The first four lines are as follows…
REDIRECT redirect.asp
WIDTH 400
HEIGHT 50
*REDIRECT
When a banner is clicked, the “AdRotator” component goes to a preliminary page.
This page is called a redirect page. The redirect page handles any extra programming events
before directing a user to the banners destination. In this example banner system, I called the
preliminary file “redirect.asp”.
WIDTH
This sets the width of the banner ad image. The value must be in pixels.
HEIGHT
This sets the height of the banner ad image. The value must be in pixels.
*
The asterisk tells the “AdRotator” component that it is about to acquire banner ad information.
The asterisk is required.
Once you define the general properties above the asterisk, then comes the list of
banners to display. In the ad.txt file, there are three banners defined below the
asterisk.
banner1.jpg
https://www.htmlgoodies.com
HTMLGoodies.com
20
banner2.jpg
http://www.yahoo.com
Yahoo.com
30
banner3.jpg
http://www.dogpile.com
Dogpile.com
30
Each banner requires four lines of properties, which follow the format below…
Image filename
Web Address
Description
Banner WeightImage File
The image filename can be a fully qualified web address or relative name that points to
the image. If the image is in a different folder, then you also include the folder
name as well.(http://www.test.com/banner1.jpg, banner1.jpg, or foldername/banner.jpg)>
Web Address
The web address can be a page on your site or a fully qualified web address that
leads to another site.
Description
The description will be displayed as a tool tip. When you rest your mouse over the
banner, the description pops up.
Banner Weight
The banner weight determines how much a banner is displayed. The “AdRotator”
component adds all of the banner weights and determines the probability or percent
chance of a particular banner being displayed. A banner with a higher weight has
better a better probability.
NOTE: You can disable a banners property by substituting with a dash.
banner3.jpg
–
Dogpile.com
30
The example entry above would create a banner ad that does not have
a web address.
Banner.asp
This file uses the “AdRotator” component and analyzes the
contents of the ad.txt file. Below is the code.
sub banner(strTarget)
dim bannerad, html
set bannerad = server.CreateObject(“MSWC.adrotator”)
bannerad.TargetFrame = strTarget
html = bannerad.GetAdvertisement(“ad.txt”)
Response.Write html
end sub
The first thing to note is that the ASP was written with VBScript. The
second thing to note is that the code is written inside a sub procedure called
banner(strTarget). For those of you who do not know, a sub procedure allows you to group
together a bunch of code that can be reused over and over. Like a function, it takes
an argument, such as a word or variable. In the code above the argument isstrTarget. Unlike a function, a
sub-procedure does not return any values, it just executes the code inside line by
line.
Inside the sub I declare two variables…
dim bannerad, html
Next I store the “AdRotator” component inside the “bannerad” variable. When storing a
component inside a variable you use thesetkeyword. Since we are programming
server-side with ASP, we use server.CreateObject to summon the component.
“MSWC.adrotator” is the component key or name value.
set bannerad = server.CreateObject(“MSWC.adrotator”)
Next I use a property of the “AdRotator” called “TargetFrame”.
This property is equivalent to…
The target-value can be one of the values below…
| _blank | Opens the destination link in a new browser window. |
|---|---|
| _top | Opens the destination link on top of the web page. |
| _parent | Opens the destination link within a parent frame. |
| _new | Opens the destination link in a new browser window. |
html = bannerad.GetAdvertisement(“ad.txt”)
Redirect.asp
Next I store a querystring value inside this new variable.
strUrl = Request.Querystring(“url”)
Redirect.asp?url=https://www.htmlgoodies.com&image=banner1.jpg