<% 'You will need to include this file, banner.asp, into any files that 'will be displaying banners. To randomly display a banner, you'll 'need only to issue the ASP command: ' ShowBanner 'That's it!! :) sub ShowBanner() 'These are constants, don't change the next 7 constants or you'll be in 'a world of pain!! Const bannerID = 0 Const bannerCategory = 1 Const bannerWeight = 2 Const advertiserID = 3 Const IMGSRC = 4 Const Description = 5 Const RedirURL = 6 '************************************************** 'OK, you WILL need to change this constant to reflect 'the directory where your root directory is housed. 'You'll also need to create two subdirectories for 'the directory listed below. These two subdirectories will 'need to be named "clicks" and "clickthrus" Const path = "c:\INetPub\wwwroot\" 'We will use the FileSystemObject Dim fs, banFile Set fs = Server.CreateObject("Scripting.FileSystemObject") 'Open banners.txt for reading Set banFile = fs.OpenTextFile(path & "Banners.txt",1) 'Read the file: Dim str str = banFile.ReadAll ' Close file banFile.Close 'Now, split the string into records Dim records records = split(str,"*") Dim banInfo(), tempArray ReDim banInfo(UBound(records),7) for i = LBound(records) to UBound(records) if right(records(i),1) = chr(10) then records(i) = left(records(i), len(records(i)) - 1) end if if left(records(i),1) = chr(10) then records(i) = right(records(i), len(records(i)) - 1) end if tempArray = split(records(i),chr(10)) banInfo(i,bannerID) = tempArray(0) banInfo(i,bannerCategory) = tempArray(1) banInfo(i,bannerWeight) = tempArray(2) banInfo(i,advertiserID) = tempArray(3) banInfo(i,IMGSRC) = tempArray(4) banInfo(i,Description) = tempArray(5) banInfo(i,RedirURL) = tempArray(6) next 'Add up all the weights Dim total total = 0 for i = LBound(records) to UBound(records) total = total + CInt(banInfo(i,bannerWeight)) next 'Randomly pick a weight randomize Dim randNum randNum = CInt(rnd * total) + 1 Dim count count = 0 total = 0 for i = LBound(records) to UBound(records) total = total + banInfo(i,bannerWeight) if randNum <= total then i = UBound(records) else count = count + 1 end if next 'Print out HREF and IMG Response.Write("
") Response.Write(vbCrLf & "") Response.Write(vbCrLf & "
" & vbCrLf & vbCrLf) 'Update impression stats... Dim strPath strPath = path & "clicks\" & banInfo(count,bannerID) & ".txt" Dim impressions if fs.FileExists(strPath) then Set banFile = fs.OpenTextFile(strPath,1) impressions = CInt(banFile.ReadLine) else Set banFile = fs.CreateTextFile(strPath,True) impressions = 0 end if impressions = impressions + 1 banFile.close Set banFile = fs.CreateTextFile(path & "clicks\" & banInfo(count,bannerID) & ".txt", True) banFile.WriteLine(impressions) banFile.close Set banFile = Nothing Set fs = Nothing end sub %>