Alternatives to Using Arrays

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Arrays provide a quick and easy way to track one-dimensional data. When you have multidimensional data, however, it can become difficult to keep track of the various subscripts; it can also become exceedingly complex to try to sort the data. Because of that, if you do have multidimensional data you might want to consider one of the these alternatives:

  • Dictionary object. The Dictionary object is part of the Script Runtime library and provides a way for you to easily store, retrieve, and modify array-like data. For more information about the Dictionary object, see "Script Runtime Primer" in this book.
  • Disconnected recordset. A disconnected recordset is a temporary database that is not tied to an actual physical database. Instead, the recordset is constructed in memory and is deleted when the script finishes. Like the Dictionary object, the disconnected recordset allows you to refer to items by name rather than by an index number. Equally important, a disconnected recordset has access to the same methods and properties as a standard recordset, including the ability to sort records. For example, the following code sample sorts a one-dimensional array:
    For i = LBound(SampleArray) to UBound(SampleArray)     For j = LBound(SampleArray) to UBound(SampleArray)         If j = UBound(SampleArray) Then         Else             If SampleArray(j) > SampleArray(j + 1) Then                TempValue = SampleArray(j + 1)                SampleArray(j + 1) = SampleArray(j)                SampleArray(j) = TempValue             End If         End If     Next Next 

    By contrast, this single line of code sorts a disconnected recordset by field name (in this case, FileSize):

    DisconnectedRecordset.Sort = "FileSize" 

    For more information about disconnected recordsets, see "Creating Enterprise Scripts" in this book.


send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net