SonghaySystem(::)

Songhay “ASP Classic” Core

This document summarizes the core include files required by our ASP web sites. This core is regarded as mature and stable and should require little modification. This is good news in view of the establishment of Microsoft’s new ASP.NET technology. Ideally, these words mark our formal departure from the “classic” ASP world, allowing research in .NET technology to go forward on a firm foundation.

The image at left shows the core ASP in the Visual Studio.NET Solution Explorer. We have three folders:

The root folder (\inc) is usually at the root of the web site and is called by a #include virtual directive.

Why VBScript?

A small but vociferous minority has innocently posed the question, “Why use VBScript on the server side instead of JScript?” The question usually comes from a person who was not brought up on a healthy diet of calorie-rich Microsoft products. This kit is designed with a large population of Visual Basic and VBA programmers in mind. Back in the late 1990s, when this kit was first starting out, these folks were the blokes claiming “ASP/IIS” experience in the resumes. So, in an effort to play well with others, VBScript was selected to make sure that the majority could hit the ground running.

The Root \inc Folder

File NameDescription
ADOVBS.aspConstants used with Microsoft’s ActiveX Data Objects (ADO). This file shipped with IIS (under a different file name).
CDOVBS.aspConstants used with Microsoft’s Collaboration Data Objects for New Technology Services (CDONTS). For us everyday folk this file was needed when you wanted to use ASP to send an email. The contents of this file is also directly from Microsoft.
rasxADO.aspConstants used with our customized COM object used to streamline ADO calls. This object is discussed in detail in “Developing a Customized COM Object for ADO.” By the year 2000, this file and its associated COM object was not used anymore in lieu of the ADO.asp VBScript class file discussed below.

The \inc\classes\ADO.asp File

This file contains the VBScript class, clsADO, which was translated from the ActiveX object discussed in “Developing a Customized COM Object for ADO.”

Property/MethodDescription
ConnectionGets the ADO Connection object associated with the instantiated object of this class.
DataErrTextGets the errors collected by the private basDataErrMsg() method.
RecordsAffectedGets the records affected by the last command run against the ADO Command object via CnnCmd() or StoredProcCmd() (if this feature is supported by the OLEDB Provider).
HasRecordsGets the Boolean after the test for whether an ADO Recordset object contains records.
Connect()

Gets the Boolean after the test for connecting to the data source with the following arguments:

DataSrc—the name of the data source (usually the NETBIOS name of the database server).

DataSrcType—specifies the OLEDB providers supported by this class: adJetOLEDB, adJet4OLEDB, adODBCOLEDB, adOracleOLEDB, adMSSQLOLEDB, adSybaseOLEDB and adUDL.

ConnectType—Specifies the connection behavior of the ADO connection object. Because this is used in ASP, this value should always be set to adConnectSynchronous.

Catalog—Specifies the name of the database for most OLEDB providers.

UserName—Specifies the name of the database user with permission to access the data.

Password—Specifies the password of the database user with permission to access the data.

TIP: By omitting the UserName and Password when calling Connect() for SQL Server 7.x (or MSDE 1.x) on Windows NT/2000, this class will use the NT/2000 login credentials to attempt to connect to the database server.

CnnCmd()

Gets the Boolean after the test for successfully executing dynamic SQL commands against the ADODB.Connection object with the arguments:

Source—Valid SQL for the DBMS. SQL strings with parameters should contain question marks (?).

Options—An ADODB.CommandTypeEnum. Only adCmdText has been extensively tested.

SQLPrms—This optional value can be an array or delimited string literal corresponding to the parameters required by Source. The string literal must be delimited by vbNullChar characters.

CnnRst()

Executes dynamic SQL projections against the ADODB.Connection object and returns a read-only, forward-only ADO Recordset.

This method has the same arguments as CnnCmd().

ClientRst()

Returns a disconnected, ADO Recordset (CursorType:=adOpenStatic and LockType:=adLockBatchOptimistic). This method is used to access ADO Recordset methods like MoveFirst() and MovePrevious(), and properties like Recordcount.

This method has the same arguments as CnnCmd().

StoredProcCmd()

Gets the Boolean after the test for successfully executing a stored procedure against the ADODB.Command object with the following arguments:

StoredProcName—Contains the name of the stored procedure of the DBMS supported by this Class.

Params—This value can be an array or delimited string literal corresponding to the parameters required by StoredProcName. The string literal must be delimited by vbNullChar characters.

NOTE: This value is passed by reference (ByRef) for stored procedure parameters that return values.

When Has2DparamArray:=True parameters passed as a two-dimensional parameter array can be updated after execution. For example, in Microsoft remote data management systems parameters modified by the OUTPUT keyword will be updated.

The 2D parameter array has the following form:

<param’ name>, <row 0>
<param’ value>, <row 0>
<param’ name>, <row 1>
<param’ value>, <row 1>

etc.

Has2DparamArray—Indicates if Params contains a two-dimensional array. See Params.

TimeOut—The number of seconds to set the CommandTimeout property of the ADO Command object. By default, it is set to 30 seconds.

StoredProcRst()

Executes a stored procedure against the ADODB.Command object and returns a read-only, forward-only ADO Recordset.

This method has the same arguments as StoredProcCmd().

CloseRecordset()

Closes the specified recordset object and sets the object to Nothing with the following argument:

RecSet—The reference to the recordset object.

Disconnect()Closes the ADO connection object.

The \inc\classes\FileSystem.asp File

This file contains the VBScript class, clsFileSystem, which handles routine calls to the file system via the Scripting.FileSystemObject and, because these calls are from ASP, the MSWC.PermissionChecker (referred to as the Permission Checker Component in the Windows 2000 Advanced Server documentation). This is a VBScript class (instead of a stateless set of routines) because, like clsADO, it is convenient to “open a connection” to a folder and “query” it several times at runtime.

Property/MethodDescription
ErrMsgGets any trappable VBScript error messages.
FSOGets the Scripting.FileSystemObject created by the class constructor.
PermissionsGets the MSWC.PermissionChecker object created by the class constructor.
WebFileNameGets/Sets the name of a file. No path information should be set here.
WebFilePathGets/Sets the path to the file set in WebFileName. This string literal must end with a backslash, \.
WebFileExists()Gets the Boolean result of the test checking for the existence and/or permissions of a file with the respect to IIS. A file object must be pre-defined by setting the WebFileName and WebFilePath properties.
WebFileObjectGets the file object associated with the call to the WebFileExists() method. The implied rule here is, You cannot have a file object without first checking for its existence.
WebFileSizeGets the size in bytes of the file object associated with the call to the WebFileExists() method.
WriteFile()

Gets the Boolean result of the test for successfully writing to a text file with the argument:

FileString—the string literal to write to the file.

A file object must be pre-defined by setting the WebFileName and WebFilePath properties. If the file does not exist, this method will create the file.

The \inc\classes\HTMLComboBox.asp File

This file contains the VBScript class, clsHTMLComboBox, which renders HTML select elements, described in Microsoft-speak as “list boxes” or “drop-down boxes.” It will be stated with pride that this method of rendering HTML was “discovered” independently and almost predates the public introduction of .NET server-side controls. It is quite a reassuring feeling that Microsoft was on the same page as our little organization—although there should be some debate about the size of this page!

Property/MethodDescription
ClassName

Gets/Sets the class attribute of the select element.

By default, the class attribute is not rendered in the HTML.

DefaultSelected

Gets/Sets the Boolean property that determines if the default value (option) of the select element is selected.

NOTE: The client-side JavaScript function jsGetOptionsIndex() is often used instead of setting this property. See “The \inc\routines\rootData.js File” below.

ID

Gets/Sets the id attribute of the select element.

By default, the id attribute is not rendered in the HTML.

JavaScript

Gets/Sets inline JavaScript used by the select element.

EXAMPLE: To add the onChange attribute to the select element, we have:

Set objCombo = new clsHTMLComboBox
objCombo.JavaScript = _
    "onChange = ""[your code here]"""

You can see how we are using the old VB double-quote trick to render the quotes in HTML. You can also see how free-form this property can be which makes it very dangerous to inexperienced users.

By default, inline JavaScript is not rendered in the HTML.

Name

Gets/Sets the name attribute of the select element.

By default, the name attribute is not rendered in the HTML.

IsMultiSelect

Gets/Sets the Boolean property that determines if this select element has a multiple attribute.

By default, the name attribute is not rendered in the HTML.

RecordsetGets/Sets the ADO recordset object used to create option elements for the select element. Only the first two columns of this recordset are used. By default, the leftmost column (column 0) sets the value attribute of the option element and the second column (column 1) is displayed.
RevColumnOrder

Gets/Sets the Boolean property that determines if the column order of the recordset or array is reversed. This means that column 1 sets the value attribute of the option element and column 0 is displayed.

This property is useful for those unfortunate cases when you are not in control of the data being sent to the client from the DBMS.

SizeGets/Sets the size attribute of the select element. By default, it is 1 (making a drop-down box); values greater than one make the list box.
Width

Gets/Sets the width attribute of the select element. This will also create an inline style attribute setting the CSS width property to make sure it renders on as many browsers as possible.

By default, this property is not used and is usually ignored because of the use of the ClassName property.

ValueList

Gets/Sets the string literal used to create option elements for the select element. This string literal is a vbNullChar-delimited list in the form:

[value] & vbNullChar & [display text] …

This implies that odd-number values in the list set the value attribute of each option element and even-number values are displayed. This design was chosen more for flexibility than for convenience.

GetComboBox()Returns an HTML string based on the properties set above. This method should only be used when the Recordset property is set.
GetComboBoxValLst()Returns an HTML string based on the properties set above. This method should only be used when the ValueList property is set.

The \inc\classes\HTMLPage.asp File

This file contains the VBScript class, clsHTMLPage, which renders entire HTML pages and common interface elements. This class was replaced by the \inc\routines\uiServices.asp file mentioned below. This class was just not flexible enough but is mentioned here for the sake of completeness and will not be documented in detail.

The \inc\classes\HTMLTable.asp File

This file contains the VBScript class, clsHTMLTable, which renders entire HTML tables. This class is the workhorse of the core and is discussed in detail in Using a Generic, Stateless VBScript Object to Display Data in a Tabular Format.

The \inc\routines\appServices.asp File

This is the “web application services” file containing generic, frequently-used VBScript routines.

RoutineDescription
basDisplayHTML()

This function truncates the text to be displayed as HTML at the specified length with arguments:

vString—the string to truncate.

vZeroString—the text to display when vString contains a zero-length string.

vLength—the length of the string to display before characters are truncated.

NOTE: Ellipses are appended to the end of a non-zero-length truncated string.

basGetGMTOffset()

This function returns the Greenwich Mean Time “offset” with respect to Pacific Time. It returns 7 when Pacific Standard Time is detected and 8 when Pacific Daylight Savings Time is detected.

This function is rather useless out of the Pacific time zone. It was developed for writing vCalendar items.

basGetMonthNames()

This function returns a one-dimensional array of month names based on the locale settings of the web server with the following argument:

vAbbreviate—Boolean value that indicates if the month name is to be abbreviated based on the locale settings of the web server.

basGetWeekDayNames()

This function returns a one-dimensional array of weekday names based on the locale settings of the web server with the following arguments:

vAbbreviate—Boolean value that indicates if the month name is to be abbreviated based on the locale settings of the web server.

vFirstDay—Numeric value indicating the first day of the week (use these constants for readability: vbUseSystemDayOfWeek, vbSunday, vbMonday, vbTuesday, vbWednesday, vbThursday, vbFriday, vbSaturday).

basGetWeekDate()

This function returns a date based on these arguments:

vWeekDay—An integer from1 to 7 corresponding to the day constants vbSunday, vbMonday, vbTuesday, vbWednesday, vbThursday, vbFriday, vbSaturday.

vWeek—An integer indicating the current week on the year (usually from 1 to 52).

vMonth—An integer indicating the current month of the year (usually from 1 to 12).

vYear—The current four-digit year.

vFirstWeekDay—An integer indicating the first day of the week (from 1 to 7 corresponding to the day constants mentioned above.).

NOTE: This function assumes that the first week of the year the week in which January 1 occurs

basGetVPath()

This function returns the virtual path in the SCRIPT_NAME environment variable as an array or as a scalar identified by vLevel with arguments:

vLevel—The level of the path to return. For example, 0 returns the file name; 1 returns the directory where the file resides.

vReturnArray—Boolean value that determines whether to return the entire array or just a scalar indicated by vLevel.

basIIf()This function is the VBScript equivalent of VBA.IIf() with arguments vCondition, vTrueResult and vFalseResult.
basInArray()

This function searches an array for a scalar value with arguments:

vArray—The array to be searched.

vItem—The search scalar.

NOTE: This converts the search scalar and each array element to strings for each search attempt.

basIsAgent()

This function is a server-side browser sniffer with argument vAgent which a string indicating the browser to detect. This is the latest list of targets:

Gecko 5x—Mozilla 5 and above.

MSIE 4x—MS Internet Explorer 4 and above.

MSIE 5x—MS Internet Explorer 5 and above.

Netscape 4x—Netscape 4 and above.

NOTE: Our client-side browser sniffer (rootSniffer.js) from webreference.com should be used for more accurate sniffing.

basLogonUser()

This function reads the LOGON_USER environment variable and returns a scalar containing the domain name or the user name—or the entire environment variable. The vItem argument determines what is returned:

When vItem="domain" the domain name is returned.

When vItem="user" the user name is returned.

All other values return the unaltered contents of the LOGON_USER environment variable.

basRandomNum()This function returns a random integer from LowerLimit to UpperLimit. The OmitList argument, a comma-delimited list of integers, is used to prevent random values matching one of the integers in the list from being returned.
basDelaySec()

This function delays code execution for the amount (in seconds) indicated by vSeconds.

This function is most useful when the Response.Buffer and Response.Flush features of ASP are used.

The \inc\routines\rootData.js File

This is the “root” file of client-side JavaScript routines that handle generic data binding and validation for web-based data editing forms.

RoutineDescription
jsGetOptionsIndex()

This JavaScript function returns an integer value indicating the index of one of the option objects in a select object with arguments:

objSelect—The select object as seen by the DOM of the web browser.

vValue_data—The value of the option object in the select object being “bound.”

This data binding function is essentially used to set the selectedIndex property of the select object.

jsGetRadioValue()This JavaScript function returns the value of the checked radio button in an array of radio buttons with the argument objRadio, the input object of type=radio as seen by the DOM.
jsGetWildCard()

This JavaScript function concatenates the wildcard character (vWildCard) of the DBMS to a search string (vString). The concatenation is determined by a code (vCode) where:

* indicates “containing.”

=* indicates “starting with.”

*= indicates “ending with.”

= indicates “exact.”

This function is made to be a part of a search form.

jsIsEmailValid()

This JavaScript function returns a Boolean value, testing the validity of email addresses with arguments:

vFormName—The name of form containing the email address input object.

objElement—The email address input object.

jsIsNotComplete()

This JavaScript function returns a Boolean value, testing for text entered in an input object with arguments:

objElement—The input object being tested.

vMsg—The message to pop up if the text field is not completed (empty).

If the text field is not complete, this function returns true.

jsIsNotNumeric()

This JavaScript function returns a Boolean value, testing for a numeric value entered in an input object. It has the same arguments as jsIsNotComplete().

If the value entered is not numeric, this function returns true.

jsIsNotSelected()

This JavaScript function returns a Boolean value, testing for an item selected in an input object where type=radio or an item selected other than the default of the select object.

It has the same arguments as jsIsNotComplete() where objElement is the radio or drop-down list box object being tested.

If the item is not selected, this function returns true.

jsIsTextConfirmed()

This JavaScript function returns a Boolean value, testing for identical values entered in two input objects of type text with arguments:

objElement1—the first input element to test.

objElement2—the second input element to test.

vMsg—The message to pop up if the text fields do not contain the same value.

If the text fields do not contain the same value, this function returns true.

jsIsTextLength()

This JavaScript function returns a Boolean value, testing for the length of text entries into input (type=text) and textarea objects (objElement) against a maximum value (vMaxLength).

If the text entered exceeds the maximum value, this function returns false and pops up an error message (vMsg).

jsIsUniqueOption()

This JavaScript function returns a Boolean value, testing for unique option values selected in a multi-select list with areguments:

objSelect—The select object to test.

vValue_data—The value to use in the test.

If the value is unique, this function returns true.

The \inc\routines\rootDates.js File

This is the “root” file of client-side JavaScript routines that handle a client-side date picker. This date picker is still under development and will be documented in a future publication.

The \inc\routines\rootMenu.js File

This JavaScript comes from Macromedia’s Andy Finnell and is used by Fireworks to make drop-down, hierarchical menus. This is another “experimental” item and may be documented later.

The \inc\routines\rootSniffer.js File

Our client-side JavaScript browser sniffer (rootSniffer.js) from webreference.com.

The \inc\routines\stringServices.asp File

This VBScript file contains string handling routines. This, the oldest file of the core, was translated out of Visual Basic 6.x and 4.x (before that, translated out of Access 97!). Many of the string handling functions were removed as Microsoft improved upon VB, VBA and VBScript. Many more functions should be replaced since the advent of Regular Expressions in VBScript (evidently introduced around 1999).

RoutineDescription
basGetCharPos()

This function returns the character position of the first character in the search string (argChars) within the string being searched (argStr).

So far, this function is very similar to Instr(). However, the argIterations argument can be used to find the nth occurrence of the search string.

If argIterations=0 then the position of the last occurrence of argChars is returned.

basGetDigits()This function returns Arabic numerals out of and will return “periods” (assumed to decimal points) if argIncludeDecimal=true.
basGetSubStr()

This function returns a substring out of argStr based on combinations of the arguments:

argStartCol—The starting column of fix-width text to extract. This column is assumed to be column 1.

argEndCol—The ending column of fix-width text to extract. This function extracts what is between the starting and ending columns.

argStartChar—The starting character of text to extract.

argEndChar—The ending character of text to extract.

These arguments can be used in any combination allowing some flexibility and some primitive form of pattern matching. However, this function is to be considered obsolete for those who can use regular expressions. When a particular parameter needs to be “turned off,” use the following default values:

argStartCol = 0
argEndCol = 0
argStartChar = vbNullString
argEndChar = vbNullString
basSearchLine()

This function returns the line containing argSearchStr, where “line” in the name of the function implies that argStr contains several vbCrLf characters.

In other words, this function responds to the request saying, “Show me the entire line of text containing the search string.”

basInsCrLf()

This function inserts vbCrLf characters at the length (or column) specified by argLineLen in argInpString.

This function was very useful back in the days when lines of text in email messages needed to be a certain length.

The \inc\routines\uiServices.asp File

This VBScript file contains “user interface services” common to many web sites. This is sort of a “smart” include file that contains one subroutine, basIncludeHTMLBlock() that takes two parameters: vBlockName and vBlockValue. The first parameter calls a particular block of HTML and the second parameter passes content that changes from call to call. The following table summarizes some the common HTML blocks:

Block NameDescription
!BOF_beginReturns the “beginning of HTML file” block. This contains the DTD and the VS.NET, VS_TARGETSCHEMA tag. The target schema tag makes it easy to maintain the uiServices.asp itself because it provides Intellisense and other VS.NET features. So far, not much “service” for the “user.”
!LINK_cssReturns a link tag calling an external CSS file. By default, it will call ./root.css. If vBlockValue is not a zero-length string then it must be relative or absolute path to an external CSS file.
!METAReturns meta tags used by search engines. This routine makes all web pages of a particular site have identical meta identification tags.
!SCRIPT_jsReturns a script tag calling an external JavaScript file. By default, it will call ./root.js. If vBlockValue is not a zero-length string then it must be relative or absolute path to an external JavaScript file.
!BOF_end

Returns the end of a “beginning of HTML file” block. This contains title elements, the end head tag and the beginning body tag.

When an “error page” is called from ASP code this HTML block is useful in making a complete web page. See below for more details.

Page

Returns a complete HTML page by calling this subroutine recursively. This is used mostly for ASP “error pages” so vBlockValue usually contains an HTML-formatted error message.

This kind of call should not be made from an ASP page if the calling page is already rendering HTML.

!EOFReturns the ending tags of an HTML page.

Our designs usually have blocks like Header or Footer. Clearly, the intention here is to centralize the handling of look and feel for web sites—even when errors are being handled. A page like this is easier to maintain with Visual Studio.NET than the VBScript class HTMLPage.asp file mentioned earlier. In fact, a web designer can create that wonderful header or footer in static HTML (like in Dreamweaver or even FrontPage) only to have it copied and pasted into a dynamic page like this one.

Free Samples and a Fond Farewell

The publishing of this document in public on the Internet marks a fond farewell to an era of ASP. This lengthy summary (which is 16 pages in Microsoft Word) records years and years of pain, misery and triumph. Now we move on to ASP.NET! Microsoft promises that this new technology will not bring as much suffering as ASP classic. In fact, the code is supposed to document itself, making pages like these obsolete.

DownloadDescription
rasxASP.zipThe \inc folder and the files mentioned above.
 
This document was last reviewed on Tuesday, April 26, 2005 at 07:06 PM PDT.
Copyright© 2008 by Bryan D. Wilhite All rights reserved. No part of this material may be used or reproduced in any form or by any means, or stored in a database or retrieval system, without prior written permission of the publisher except in the case of brief quotations embodied in critical articles and reviews. Making copies of any part of this material for any purpose other than your own personal use is a violation of United States copyright laws.

The information provided by Bryan D. Wilhite at kintespace.com is provided “as is” without warranty of any kind. In no event shall Bryan D. Wilhite or any of his affiliates be liable for any damages whatsoever including, but not limited to, direct, indirect, incidental, consequential, loss of business profits or special damages due to material published by Bryan D. Wilhite or any of his affiliates.