What's a Component?
A component is just a piece of code someone wrote so you wouldn't have to re-invent the wheel. Just like when you create a subroutine, you use the same code over and over again instead of having to re-write virtually the same piece of code somewhere else.
Why use Components?
Components make programming easier. You don't have to use components, but you will be creating much more work for yourself then needed.
Using the Ad Rotator Component
What's the Ad Rotator Component? Just what is says. It rotates your ads for you. In order to use this component, you will need three things:
1. The rotator schedule file (text file)
2. ASP page that redirects the user
3. The ASP page that houses the banners
First, let's create the schedule file. A schedule file will have the following format:
schedulefile.txt
|
redirect.asp
width
height
border
*
ImageURL
HomePageURL
AltText
Weight
Image2URL
HomePage2URL
AltText
Weight |
The first 4 lines of code apply to all banners.
The first line of code tells the browser what file to go to once the banner it clicked. This could be a redirecting script that logs all hits out from your site.
The second and third lines of code affects the width and height of the banners while the fourth line of code sets a border width around the image.
The fifth line of code (*) indicates where the first section of the file stops and the second starts.
ImageURL is the path of your banner
HomePageURL is the URL that the user is taken to when they click on the banner. This URL is passed to the redirect URL for processing. If there is no site to be taken to, then a hyphen (-) should be used.
AltText is used to display text instead of an image if the image doesn't load.
Weight is a number between 0 and 10,000 that indicates how many times the ad should be display compared to all other banners in the schedule file. For instance, if you had two banners in the schedule file with the weight of 1o and one banner with the weight of 20, the banner with weight 2o would be shown more times then the first two banners.
Here's a live example:
schedulefile.txt
Now on to the redirection page. This page will redirect the user to the appropriate site when a banner is clicked.
The Ad Rotator creates a querystring for us to use. When a user clicks on a banner, we will get a querystring with the following information:
| redirect.asp?url=homepageURL&image=imageURL |
So if we want to redirect the user to the appropriate site, we would use the following line of code:
redirect.asp
| <% Response.Redirect Request.QueryString("URL")%> |
The last file we need to create is the ASP page(s) that will display the banners.
index.asp
|
<%
Dim objAdRotator
Set objAdRotator = Server.CreateObject("MSWC.AdRotator")
%>
<HTML><HEAD>
<TITLE>My Site </TITLE>
</HEAD><BODY>
Please support this site!<BR>
<%= objAdRotator.GetAdvertisement("schedulefile.txt") %>
Set objAdRotator = Nothing
<BR>Welcome to my site!!!
</BODY></HTML> |
This page displays our banners. If you refresh this page several times, you will see that a different image is displayed. Sometimes, especially with fewer banners to display, the same banner will appear.
The first couple of lines of code creates an instance of the Ad Rotator object and gives it the name of objAdRotator.
To display our image, we use the following code like shown above:
| <%= objAdRotator.GetAdvertisement("schedulefile.txt") %> |
As you can see, our object uses the method GetAdvertisement() with the property of the name of our schedule file.