After playing with ASP for a while I figured out what I would need and started off programing with a internet browser open to w3schools asp page. My idea is grab a config file read it in and choose a random ad from it and display. At first I though of using ajax to pull the content, however I would rather avoid using ajax, because if javascript is not turned on then no ads will be displayed. Instead I like that fact that you can include asp pages and then call the function, this also allows you to specify a width, and maybe if needed I will add some other parameters later. So far works quite well, but still is in development.
ASP Generator
<%
'//////////////////////////////////////////////////////////////////////////
'Display ads when function is called
'//////////////////////////////////////////////////////////////////////////
function displayAd(width)
config = Array()
config = ReadConfigFile("///path to config file///")
' Count the elements in the array
dim count
for each arrValue in config
count = count+1
next
'Will give the correct ad count based off of interger division + 1
count = count \ 4 + 1
randomize()
adchoice = 4 * Int(count * Rnd)
Response.Write "<div class='" & config(adchoice+2) & "' style='background-color: " & config(adchoice+1) & "; width: " & width & "'>"
Response.Write "<p>" & config(adchoice) & "</p>"
Response.Write "</div>"
end function
'//////////////////////////////////////////////////////////////////////////
'Read from file and grab contents for ad display
'//////////////////////////////////////////////////////////////////////////
function ReadConfigFile(Filename)
const ForReading = 1, ForWriting = 2, ForAppending = 3
const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
strAllFile = Array()
' Create a filesystem object
dim FSO
set FSO = server.createObject("Scripting.FileSystemObject")
' Map the logical path to the physical system path
dim Filepath
Filepath = Server.MapPath(Filename)
if FSO.FileExists(Filepath) Then
set TextStream = FSO.OpenTextFile(Filepath, ForReading, false, TristateUseDefault)
' Read file in one hit
Counter = 0
do while not (TextStream.AtEndOfStream)
redim preserve strAllFile(Counter)
strAllFile(Counter) = TextStream.ReadLine
Counter = Counter + 1
loop
TextStream.Close
else
Response.Write "<h3><i> Config does not exist </i></h3>"
end if
set FSO = nothing
ReadConfigFile = strAllFile
end function
%>
Include & call
<!--#include file="adgenerator.asp"-->
<% displayAd(300) %>
Config file test
This is a ad in a rounded box...
#999999
adboxround'
This an ad in a box...
#235689
adboxsquare
No comments:
Post a Comment