So now most all of the default.asp homepage has been assembled by opening simple text files and filling the areas with the text file content. Suddenly this whole page can be left alone for long periods of time. If you make a mistake in the text file, this normally won't affect operations at all. Your customers may think twice...oooops.
Ok, there's no browser checking, just a little code for noframes, this is very basic. Most developers of websites must be concerned with the user viewpoint and supporting the content for a variety of browsers is a fairly common procedure. There are two strategies for this, send javascript to the client and document.write at the places on a page where browser detection is needed; or, detect from the HTTP headers what browser is making the request and send a static page.
What the overall design intends to do has a great influence on the presentation of the page. Design elements in this case were composed of frames. The text file system can also produce composite single pages with this same source material. This would avoid the frames issue entirely by producing a page with tables instead.
To begin, the code for the banner is simple, just some font tags.
<div align="center"><b><font face="Book Antiqua" size=4><font size=6>O</font>nline<font size=6>A</font>rticles and <font size=6>P</font>hotography</font></b></div>
In this example the main page is constructed in pieces as before. The graphic used is the ASP ad rotator component, the text is in a separate text file with the footer table also a separate file, and all this will now be used to produce a set of tables to replicate the look of frames. Using only tables allows the content to be seen by almost any browser, which is best for a homepage, as is plain html. Using even javascript runs into trouble for a wide audience, yet that doesn't apply to LAN's as much, where the scripting can perform many business rules without server hits; something to always keep in mind.
The code
Creating a default.asp
In this case, typical code to create the frames version of the page:
<!-- DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2 Final//EN'-->
<html>
<head>
<title>Outdoor Photography and Other Interests</title>
</head>
<frameset rows="44,*" frameborder="yes" framespacing="1" border="1">
<frame name="banner" src="banner_01.asp" marginwidth="3" marginheight="3" scrolling="auto" frameborder="no">
<frameset cols="106,*">
<frame name="nav" src="nav_01.asp" marginwidth="3" marginheight="2" scrolling="auto" frameborder="no">
<frame name="main" src="main_01.asp" marginwidth="6" marginheight="6" scrolling="auto"frameborder="no">
</frameset>
<noframes>
<body>
Your browser does not support frames so won't be able to view this website, please download an up to date browser as no text-only navigation is available.
</body>
</noframes>
</frameset>
</html>
Examining the main page, it has a content text file, then the ad rotator and finally the footer is added from another text file.
dim main_obj, main_file, main_content set obj_ad = server.createobject("Scripting.FileSystemObject") set ad_file = obj_ad.opentextfile("D:/webshare/wwwroot/asp/examples/main_content.txt") on error resume next
main_content = ad_file.readall
This has the file main_content.txt open and moved into the variable main_content. Next I'll insert the ad rotator which is supported by two other test files!! These control what images are displayed and the URL's for links. The first of these is called the schedule file as it defines the amount of relative time each ad gets, as well as the graphic size and sources:
REDIRECT ad_urls.asp
WIDTH 96
HEIGHT 64
BORDER 1
*
/gifs/xcntry_01.gif
http://tommalla/asp/examples/default_4.asp
Online articles and photography
2
/gifs/xcntry_02.gif
http://tommalla/asp/examples/default_4.asp
Other online articles and photography
2
This simple two entry example uses the 96x64 pixel with border image to flip, there is no text.
dim mainfile, fileObj set fileObj = createobject("Scripting.FileSystemObject")
Did the object get created? If yes, open the file:
if isobject(fileObj) then set mainfile = fileObj.opentextfile("D:\webshare\wwwroot\asp\main_content.txt")
As before, an error can occur here if the file isn't found, or can't be opened by the system so having an on error statement is important to keep the client application from hanging. To handle this error one could use a default list in memory which was included at runtime, or hard-coding URL's which are used on file system errors (404's). The error code to create a default dictionary would look something like:
on error resume next
dicObj.item("default.htm") = "Industrial Design and Other Interests"
dicObj.item("products.htm") = "An Interesting Array of Products"
dicObj.item("prices.htm") = "Current Pricing"
dicObj.item("technical.htm") = "Technical Details of All Products"
dicObj.item("white_papers.htm") = "White Papers Outlining Features and Scope"
dicObj.item("support.htm") = "Contact Our Friendly Support Crew"
dicObj.item("archive.htm") = "Dive Into the Archives for Facts"
The code now has main_content.txt open in read-only mode if there wasn't an error. To read a line you code a statement:
while not mainfile.atendofline dim main
main = mainfile.readline
Again we need to separate this string which is separated by a comma. Instr() is used to find a place, and mid() is used to retrieve it. With two variables, two mid()'s will retreive the key and value.
For redirecting the urls, this coding is in the url file used by the rotator.
dim gothere
gothere = request.querystring("url") response.redirect(gothere)
Then there is the footer, stored from another text file of course.
dim ad_obj, ad_file, ad_content set obj_ad = server.createobject("Scripting.FileSystemObject") set ad_file = obj_ad.opentextfile("D:/webshare/wwwroot/asp/examples/footer_01.txt") on error resume next
ad_content = ad_file.readall response.write(ad_content)
It looks like all the pieces are ready to build the dynamic part of the coding now. I'll have to create a master table and plot layouts to get a similar design to the frames version. This is nested tables, with the choice of either specifying percentages or absolute size in pixels as the usual methods of doing this. The outer table is a 100% wrapper with the first row the banner. Absolute pixels are used to control the look, percentages would be fine for many designs but here it looks weird when the nav bar resizes.
Seems to look about right. So, to assemble the page dynamically, these pieces will flow together as below.
<%@ Language="VBScript"%>
<%response.buffer = True%>
<% response.write("<!-- DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2 Final//EN'-->") response.write("<html>") response.write("<head><title>Website Navigation Page</title>") response.write("</head>") response.write("<body>") response.write("<font face='verdana,arial,helvetica' size=2>") response.write("<table width=640 border=1 cellspacing=0 cellpadding=1>")
dim abanner, bannertext, fileObj set fileObj = createobject("Scripting.FileSystemObject") if isobject(fileObj) then set abanner = fileObj.opentextfile("D:\webshare\wwwroot\asp\examples\banner.txt")
bannertext = abanner.readall end if response.write("<tr><td border=1 colspan=2 align=center valign=middle bgcolor=ffffff>" & bannertext & "</td></tr>")
abanner.close set fileObj = nothing %>
<% response.write("<tr><td width=48 rowspan=3 align=center valign=top bgcolor=ffffff>") dim objfile, navfile, navout set objfile = createobject("Scripting.FileSystemObject") if isobject(objfile) then set navfile = objfile.opentextfile("D:\webshare\wwwroot\asp\examples\nav.txt") end if while not navfile.atendofline dim nav
nav = navfile.readline
navout = navout & "<tr><td bgcolor=ccffcc height=24>" & nav & "</td></tr>" wend
navtable = "<table>" & navout & "</table>" response.write(navtable & "</td><td width=592>") %>
<% dim main_obj, main_file, main_content set main_obj = server.createobject("Scripting.FileSystemObject") set main_file = main_obj.opentextfile("D:/webshare/wwwroot/asp/examples/main_content.txt")
main_content = main_file.readall
dim foot_obj, footer_file, footer set foot_obj = server.createobject("Scripting.FileSystemObject") set footer_file = foot_obj.opentextfile("D:/webshare/wwwroot/asp/examples/footer_01.txt")
footer = footer_file.readall
What this code does
It creates an entire homepage using the file system object which allows the data to be changed without changing the code for the page. It takes souce material from this variety of files to construct the page and does this without using frames. This page is viewable by most browsers, containing only tables as a feature which may not display in older browsers. This technique is very similar to using databases without the connection overhead versus the file system which is integrated directly into the operating system's I/O api's. The next idea will be how this maps directly to using a database and tables, first using the Dictionary object for rudimentary sorts and compares (still powerful for many tasks) followed by articles on mapping directly into databases and sql queries.
Double quotes separated from single quotes for clarity, don't do this !
Previous versions of VBScript are CaseSensitive, this is written for the latest version.
Development Test System: Windows98, PentiumII 200MHz 128Mb
Personal Web Server 4.0 (IIS4), SQL7b3, Personal Oracle, Sybase