VBA array sort function?

后端 未结 13 2217
北荒
北荒 2020-11-22 05:28

I\'m looking for a decent sort implementation for arrays in VBA. A Quicksort would be preferred. Or any other sort algorithm other than bubble or merge would suffice.

<
13条回答
  •  忘了有多久
    2020-11-22 06:11

    Dim arr As Object
    Dim InputArray
    
    'Creating a array list
    Set arr = CreateObject("System.Collections.ArrayList")
    
    'String
    InputArray = Array("d", "c", "b", "a", "f", "e", "g")
    
    'number
    'InputArray = Array(6, 5, 3, 4, 2, 1)
    
    ' adding the elements in the array to array_list
    For Each element In InputArray
        arr.Add element
    Next
    
    'sorting happens
    arr.Sort
    
    'Converting ArrayList to an array
    'so now a sorted array of elements is stored in the array sorted_array.
    
    sorted_array = arr.toarray
    

提交回复
热议问题