vbscript – transform a list into an index/dictionary list (to reduce size of array)

transform a list (array) into an index and dictionary list to reduce size of list
a1 – initial list with duplicates
a2 – returns index array
a3 – returns dictionary array (distinct / unique array)
to rebuild the original array use a3(a2(i)), where i is the index of the index of the original list

Sub lookup1(a1, a2, a3)
    'build's a lookup for a1: a2=index,a3=dictionary
    Dim i, j, k
    ReDim a2(UBound(a1))
    ReDim a3(0)
    a3(0) = a1(0)
    For i = 0 To UBound(a1)
        k = a1(i)
        For j = 0 To UBound(a3)
            If k = a3(j) Then Exit For
        Next
        If j > UBound(a3) Then
            ReDim Preserve a3(j)
            a3(j) = k
        End If
        a2(i) = j
    Next
End Sub
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s