Solved

# re-arrange array values -highest to lowest  VB6

Posted on 2006-04-11
Medium Priority
973 Views
Last Modified: 2008-02-01
Hi,

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

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

output:
5,4,2,3,1,12,100

how can we re-arrange to output as:
100,12,5,4,3,2,1

Thanks.

0
Question by:DexterJones
• 2
4 Comments

LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 1000 total points
ID: 16428939
0

LVL 8

Assisted Solution

Leo Eikelman earned 1000 total points
ID: 16430597
This link from Microsoft shows how to do bubble sort, selection sort, and shell sort:

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/Q169/6/17.asp&NoWebContent=1

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

Cheers,

Leo
0

Expert Comment

ID: 16433830
how do we call the sub ?

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

Thanks
0

LVL 8

Expert Comment

ID: 16435222
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

Leo
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
###### Suggested Courses
Course of the Month15 days, 22 hours left to enroll

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

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