It was once suggested that I incorporate "captions" with an ASP/JavaScript Slide Show Application that I had designed. Although I never had any personal requirement to use captions, the idea seemed like an interesting challenge, because those captions should be dynamic.  In other words, just like the images, the captions for each picture should be pulled into the page programmatically. Well, this brought me to look into the FileSystemObject and the following design.


For image stock on this experiment, I used pictures from the Auto-Cross that my friends Chuck, Dinah, and I attended in September, 1999. The photos were taken with my Olympus C2000 Zoom. The day was beautiful, and the fun we had was outrageous!


The design concept turned out to be fairly simple. Each of the pictures in the slideshow are named sequentially as "1.jpg", "2.jpg", etc., and they reside in their own sub-folder, in this case the sub-folder is called "autocross".

In addition to the image files, there is a text file in that sub-folder called "contents.txt". This text file has a dual purpose; the first line in the text file is used as the Slide Show Title (in this case, "Sunday at the Auto-Cross".)Auto-Cross Caption File  Each subsequent line of text is directly related to each image.  In other words, text line number 4 is the caption used for picture "3.jpg", and so on.  For this Auto-Cross experiment, click here to see the text file I used.

And last, the VBScript used in this Active Server Page. Of course, there is more to the page functionality than just this script. ASP assignments are used for each VCR button, the Refresh metatag, and the window title.  As well, there is a combination of JavaScript and ASP used to pre-load the next image in the loop, and a simple "CloseWindow" JavaScript function. But really, the bulk of the logic for this design is in the file naming conventions, the folder configuration, and the following VBScript found in the header of the Active Server Page:


<%
DIM strCat, strFolder, strFile, strTitle, strCaption
DIM lngInd, lngMax, lngPrev, lngNext, lngCtr
DIM objFSO, objText, objFolder, objFiles

strCat    = cStr(Request.QueryString("cat"))
lngInd    = cLng(Request.QueryString("ind"))
strFolder = server.MapPath(strCat)
strFile   = server.MapPath(strCat & "\contents.txt")

Set objFSO    = CreateObject("Scripting.FileSystemObject")
Set objText   = objFSO.OpenTextFile (strFile)
Set objFolder = objFSO.GetFolder(strFolder)
Set objFiles  = objFolder.files

lngMax  = objFiles.count - 1
lngPrev = lngInd - 1
lngNext = lngInd + 1

If (lngPrev < 1) Then lngPrev = lngMax
If (0 > lngMax - lngNext) Then lngNext = 1

strTitle = objText.ReadLine

For lngCtr = 1 to lngInd
   strCaption = objText.ReadLine
Next

objText.close

Set objFSO    = Nothing
Set objText   = Nothing
Set objFolder = Nothing
Set objFiles  = Nothing
%>


In retrospect, the easiest part of this little experiment was figuring out the design, and then it was a simply a matter of discovering the objects and syntax necessary to build it.

Home  •  Photos   Toys   Misc   Contact