re-arrange array values -highest to lowest  VB6

Posted on 2006-04-11
Last Modified: 2008-02-01

Please kindly assist how can we re-arrange array values? highest to lowest using VB6

Dim Arr_First5Highest(6) As Integer
Debug.Print Join(Arr_First5Highest(6), ",")


how can we re-arrange to output as:


Question by:DexterJones
    LVL 142

    Accepted Solution

    LVL 8

    Assisted Solution

    by:Leo Eikelman
    This link from Microsoft shows how to do bubble sort, selection sort, and shell sort:

    Here is a simple bubble sort

    Sub BubbleSortNumbers(iArray As Variant)
      Dim lLoop1 As Long
      Dim lLoop2 As Long
      Dim lTemp As Long

      startTime = Time()
      For lLoop1 = UBound(iArray) To LBound(iArray) Step -1
        For lLoop2 = LBound(iArray) + 1 To lLoop1
          If iArray(lLoop2 - 1) < iArray(lLoop2) Then
            lTemp = iArray(lLoop2 - 1)
            iArray(lLoop2 - 1) = iArray(lLoop2)
            iArray(lLoop2) = lTemp
          End If
        Next lLoop2
      Next lLoop1
      endTime = Time()
      timeToSort = endTime - startTime
      timeTaken = "Bubble Sort: " & timeToSort
    End Sub



    Expert Comment

    how do we call the sub ?

    BubbleSortNumbers(Arr_First5Highest(),0,6)   <---returned an error type mismatch: array or user defined type expected

    LVL 8

    Expert Comment

    by:Leo Eikelman
    Is Arr_First5Highest() an array of Integers or Long?

    If you are using:
    Sub BubbleSort (List() As Long, ByVal min As Integer, _
        ByVal max As Integer)

    It expects an array of Long values


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now