Export (0) Print
Expand All

Alternatives to Using Arrays

Microsoft® Windows® 2000 Scripting Guide

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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft