% 'article.asp - Program to display one of Louie Celerier's Bits & Pieces articles..
' The default script (default.asp) displays a table of contents of the articles, and then
' calls this script to display one article. It passes one query string parameter:
' id=the base filename.
' There should be a .htm file with that base filename.
' The base filename is a date in yyyy-mm-ddx format, with x being an optional letter that
' allows multiple articles to occur on the same date.
' This script is VERY similar to article.asp in the letters subdirectory, and the terms
' "article" and "letter" are synonymous.
'
Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
dim articles, articleDate(100), articleTitle(100) 'Up to 100 articles
articles = 0 'Counts the articles as they are read, and then as they are displayed
Dim dashdate, pagetitle, slashdate, shortdate, thisarticle
shortdate = "(Requested article is not in the index!?!)"
'Build our own array of month names for date conversion.
dim months
months = Array("","January","February","March","April","May","June","July","August","September","October","November","December")
'**** Read the index file into an array of file identifiers (essentially, dates), and an array of titles.
'**** We need these arrays to help with links to the next and previous article.
dim FSO, filename, Filepath, file, TextStream, Line
filename = "index.txt"
' Create the filesystem object, then map the logical path to the physical system path
set FSO = server.createObject("Scripting.FileSystemObject")
Filepath = Server.MapPath(Filename)
if FSO.FileExists(Filepath) Then
' Get file handle and open the file.
set file = FSO.GetFile(Filepath)
Set TextStream = file.OpenAsTextStream(ForReading, TristateUseDefault)
' Read the index file line by line, and store every line in the arrays articleDate() and articleTitle()
Do While Not TextStream.AtEndOfStream
Line = TextStream.readline
'Read 11 characters. One character after the date allows more than one article to appear on the same date.
dashdate = trim(left(line,11)) 'yyyy-mm-ddx
pagetitle = mid(line,12) 'may contain
tags
articles = articles + 1
articleDate(articles) = dashdate
articleTitle(articles) = pagetitle
'If this is the article that has been requested, save its index number in thisarticle, and
'convert its date to a MMMMMM dd, yyyy format.
If request.querystring("id")=dashdate Then
thisarticle = articles '
if right(dashdate,1)="x" Then
shortdate="" 'For articles that don't have a valid date.
else shortdate = months(cint(mid(dashdate,6,2))) & " " & trim(cint(mid(dashdate,9,2))) & ", " & left(dashdate,4)
End If
End If
Loop
articleDate(articles+1)="" 'Make sure the list ends with an empty entry, not "null"
Set TextStream = nothing
Else %>
Major error!! The index of articles is missing. Please try again later.
"
Response.Write "If this error persists, please notify us
" & vbcrlf <% Response.End End If Set FSO = nothing %>
Link directly to the PDF for printing
" & vbcrlf response.write "- Luis R. Celerier"
response.write "
Longview, Texas
Sorry - there is no article at " & request("id") & ".htm
" & vbcrlf End If Set FSO = nothing End If %> <%'================================================================= ' Functions and Subroutines '=================================================================== 'Convert the yyyy-mm-ddx-formatted date stored in the array into a parenthesized ddMMMyy format. 'The array of months gives full month names; we just want the first 3 letters here. Function linkdate(i) dim thedate thedate = articledate(i) linkdate = "(" & mid(thedate,9,2) & left(months(cint(mid(thedate,6,2))),3) & left(thedate,4) & ")" End Function %>