<-- Previous || Up || Next -->

Sort Variant Matrix Rows Sample Sub
Array Sorts Class

Private Sub SortVariantMatrixRowsSample()

    'See also:
    '  SortVariantMatrixRows2ndSample Subroutine
    '  SortVariantMatrixRows Function

    Const NumSamples = 4096
    Const fShow = False

    Dim avarOrig() As Variant
    DirToVariantVector avarOrig, CombinePathAndFile(GetWindowsDirectory, "*.*"), Null, False, False, False, False

    '' Create a variant matrix containing some of the file names.

    Dim avarMatrix() As Variant
    ReDim avarMatrix(0 To 2, 0 To UBound(avarOrig))

    Dim avarKeys() As Variant
    ReDim avarKeys(0 To 2)

    Dim lngCurFIle As Long
    For lngCurFIle = 1 To UBound(avarMatrix, 2)
        avarMatrix(1, lngCurFIle) = RandomIntegerWithinRange(1, UBound(avarMatrix, 2))
        avarMatrix(2, lngCurFIle) = avarOrig(lngCurFIle)
    Next lngCurFIle

    ReDim Preserve avarMatrix(LBound(avarMatrix, 1) To UBound(avarMatrix, 1), LBound(avarMatrix, 2) To Min2Real(NumSamples, UBound(avarMatrix, 2)))

    If fShow Then Debug.Print FormatVariantMatrix(avarMatrix, " ", vbCrLf)

    avarKeys(1) = 1
    avarKeys(2) = 2
    Debug.Print "SortVariantMatrix (Rnd) to (1,2):"
    DebugTimerOn
    SortVariantMatrixRows avarMatrix, Null, avarKeys, False
    Debug.Print DebugTimerOff

    If fShow Then Debug.Print FormatVariantMatrix(avarMatrix, " ", vbCrLf)

    avarKeys(1) = 1
    avarKeys(2) = 2
    Debug.Print "SortVariantMatrix (1,2) to (1,2):"
    DebugTimerOn
    SortVariantMatrixRows avarMatrix, Null, avarKeys, False
    Debug.Print DebugTimerOff

    If fShow Then Debug.Print FormatVariantMatrix(avarMatrix, " ", vbCrLf)

    avarKeys(1) = 2
    avarKeys(2) = 1
    Debug.Print "SortVariantMatrix (1,2) to (2,1):"
    DebugTimerOn
    SortVariantMatrixRows avarMatrix, Null, avarKeys, False
    Debug.Print DebugTimerOff

    If fShow Then Debug.Print FormatVariantMatrix(avarMatrix, " ", vbCrLf)

    avarKeys(1) = 2
    avarKeys(2) = 1
    Debug.Print "SortVariantMatrix (2,1) to (2,1):"
    DebugTimerOn
    SortVariantMatrixRows avarMatrix, Null, avarKeys, False
    Debug.Print DebugTimerOff

    If fShow Then Debug.Print FormatVariantMatrix(avarMatrix, " ", vbCrLf)

    avarKeys(1) = 1
    avarKeys(2) = 2
    Debug.Print "SortVariantMatrix (2,1) to (1,2):"
    DebugTimerOn
    SortVariantMatrixRows avarMatrix, Null, avarKeys, False
    Debug.Print DebugTimerOff

    If fShow Then Debug.Print FormatVariantMatrix(avarMatrix, " ", vbCrLf)
End Sub

Copyright 1996-1999 Entisoft
Entisoft Tools is a trademark of Entisoft.