Variant array of strings

Discussion in 'AutoCAD' started by VBA, Dec 9, 2004.

  1. VBA

    VBA Guest

    I have a variant array of string values [i.e. Dim Unsorted As Variant] and I
    want to sort them.

    Does anyone have a routine that will accomplish this task?

    TIA
     
    VBA, Dec 9, 2004
    #1
  2. '*********
    ' Bubble Sort an array of any type
    ' Author: The VB2TheMax Team
    Sub BubbleSort(arr As Variant, Optional descending As Boolean, _
    Optional numEls As Variant)

    Dim Value As Variant
    Dim Index As Long
    Dim firstItem As Long
    Dim indexLimit As Long, lastSwap As Long

    ' account for optional arguments
    If IsMissing(numEls) Then numEls = UBound(arr)
    firstItem = LBound(arr)
    lastSwap = numEls

    Do
    indexLimit = lastSwap - 1
    lastSwap = 0
    For Index = firstItem To indexLimit
    Value = arr(Index)
    If (Value > arr(Index + 1)) Xor descending Then
    ' if the items are not in order, swap them
    arr(Index) = arr(Index + 1)
    arr(Index + 1) = Value
    lastSwap = Index
    End If
    Next
    Loop While lastSwap
    End Sub
    '**********
     
    Paul Richardson, Dec 9, 2004
    #2
  3. VBA

    Jorge Lopez Guest

    Jorge Lopez, Dec 9, 2004
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.