'==========================================================================
' NAME: DrivesRecordset.vbs
'
' COMMENT: Exposes drive information through an ADO recordset
'==========================================================================
' Constants
Const adUseClient = 3
Const adCurrency = 6
Const adBSTR = 8
' Local variables
Dim fso, rst, drives
' Creates the main objects of the script
Set fso = CreateObject("Scripting.FileSystemObject")
Set rst = CreateObject("ADODB.Recordset")
' Gets the collection of available drives
Set drives = fso.Drives
' Prepares the recordset structure: Root, Volume, Type, FileSystem, FreeSpace
rst.CursorLocation = adUseClient
rst.Fields.Append "Root", adBSTR
rst.Fields.Append "Volume", adBSTR
rst.Fields.Append "Type", adBSTR
rst.Fields.Append "FileSystem", adBSTR
rst.Fields.Append "FreeSpace", adCurrency
rst.Open
' Fills the recordset out with drive information
for each drv in drives
rst.AddNew
if drv.IsReady then
rst.Fields("Root").Value = drv.DriveLetter
rst.Fields("Volume").Value = drv.VolumeName
rst.Fields("Type").Value = drv.DriveType
rst.Fields("FileSystem").Value = drv.FileSystem
rst.Fields("FreeSpace").Value = drv.FreeSpace /1024
end if
next
' Displays the recordset
s = ""
rst.MoveFirst
while Not rst.EOF
for each fld in rst.Fields
s = s & Pad(rst.Fields(fld.Name), 14) & vbTab
next
s = s & vbCrLf
rst.MoveNext
wend
MsgBox s
'==========================================================================
' Pad(str, numChars)
' Pads the specified string with the specified trailing blanks
'==========================================================================
Function Pad (str, numChars)
str = str & Space(numChars)
Pad = Left(str, numChars)
End Function
Figure 3
Creating a JavaScript Object
'<SCRIPT RUNAT="SERVER" LANGUAGE="JavaScript">
// JsRecordset.js
// Provides a JavaScript implementation of ADO recordsets
// Creates a new object with as many fields as specified
// INPUT: <fields> it's a reference to an ADO Fields object
function Record(fields)
{
var i;
// Add a new named property for each field in the recordset
for (i=0; i<fields.Count; i++) {
cmd = "this." + fields.Item(i).Name + " = \"" +
fields.Item(i).Name + "\"";
eval(cmd);
}
}
// Creates and fills a new array with as many records as the
// specified ADO recordset
// INPUT: <rst> it's a reference to an ADO recordset object
function Recordset(rst)
{
// Define the Items property being the collection of records
this.Items = new Array();
var i=0;
var cmd = "";
// For each record in the recordset creates a Record object
// and populates its properties with the values
numOfFields = rst.Fields.Count;
while (!rst.EOF) {
this.Items[i] = new Record(rst.Fields);
for (j=0; j<numOfFields; j++)
{
cmd = "this.Items[i]." + rst.Fields.Item(j).Name +
" = String(rst.Fields.Item(j).Value)";
eval(cmd);
}
rst.MoveNext();
i++;
}
// Define the length property counting the records
this.length = i;
}
// Rebuilds the JavaScript Recordset object from a
// serialized version of it.
// INPUT: <string representing a serialized RS>
function EvalRS(strRS)
{
// The original string is in the form:
// <RETURN_VALUE...><METHOD...>
// var undefined; ...
// </RETURN_VALUE></METHOD>
// Unescapes the original string
strOriginal = unescape(strRS);
// The string we're interested in begins with 'var
// undefined;'
pos = strOriginal.indexOf("var");
strRawData = strOriginal.substr(pos);
// Removes the closing tags
pos = strRawData.indexOf("</RETURN_VALUE></METHOD>");
strRawData = strRawData.substring(0,pos);
// Rebuilds the object and returns
return eval(strRawData);
}
</SCRIPT>
Figure 5
Putting Fields into an Array
<SCRIPT LANGUAGE="javascript">
var serverURL = "https://expoware";
var pageURL = "/mind/rs/server/EmpData2.asp";
function refreshPage(co)
{
if (co.status == 0) {
oRS = co.return_value;
if (oRS.length == 0) {
empName.innerText = "";
empCity.innerText = "";
empTitle.innerText = "";
empHired.innerText = "";
errLog.value = "No record found.";
return;
}
empName.innerText = oRS.Items[0].EmployeeID +
" - " + oRS.Items[0].TitleOfCourtesy + " " +
oRS.Items[0].FirstName + " " +
oRS.Items[0].LastName;
empTitle.innerText = oRS.Items[0].Title;
empCity.innerText = oRS.Items[0].City + " " +
oRS.Items[0].Region + ", " +
oRS.Items[0].Country;
d = new Date(oRS.Items[0].HireDate);
empHired.innerText = (1+d.getMonth()) + "/" +
d.getDate() + "/" + d.getYear();
}
}
function errHandler(co)
{
if (co.status != 0)
co.context.value = co.message;
}
function execCall()
{
errLog.value = "";
var co = RSExecute(serverURL+pageURL,"GetEmployeeInfo",
txtEmpName.value,
refreshPage, errHandler, errLog);
}
</SCRIPT>
Figure 6
Getting Specific Fields
<<%@ LANGUAGE=VBSCRIPT %>
<% RSDispatch %>
<SCRIPT RUNAT=SERVER Language="JScript">
<!--#INCLUDE VIRTUAL="/_ScriptLibrary/RS.ASP"-->
<!--#INCLUDE VIRTUAL="/_ScriptLibrary/JSRECORDSET.ASP"-->
var adUseClient = 3;
function Description()
{
this.GetEmployeeInfo = DoGetEmployeeInfoAsRecordset;
}
public_description = new Description();
function DoGetEmployeeInfoAsRecordset(empName)
{
sql = "select ";
sql += "EmployeeID, FirstName, LastName,
TitleOfCourtesy, ";
sql += "City, HireDate, Region, Country, Title ";
sql += "from Employees where LastName='"
sql += empName + "'";
rst = new ActiveXObject("ADODB.Recordset");
rst.CursorLocation = adUseClient;
rst.Open(sql, "NW");
oRS = new Recordset(rst);
rst.Close();
return oRS;
}
</SCRIPT>