x
Solved

# Sorting variables in array

Posted on 1999-01-26
Medium Priority
217 Views
Okay, I have an array filled with six randomly chosen integers:
numb(1 to 6)
How do I sort them so that numb(1) is lowest and numb(6) is highest?
For Example:
15, 19, 25, 28, 47, 66
0
Question by:timothy1
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 13

Accepted Solution

Mirkwood earned 200 total points
ID: 1470726
Sure here is a sample

Option Explicit
Dim arr(6) As Integer

Private Sub Command1_Click()
sort arr
List1.Clear
Dim i As Integer
For i = 0 To 6
Next
End Sub

Dim i As Integer
For i = 0 To 6
arr(i) = Rnd() * 100
Next
End Sub

Private Sub sort(ByRef arr As Variant)
Dim i As Integer
Dim j As Integer
Dim t As Variant

For i = LBound(arr) To UBound(arr)
For j = LBound(arr) To UBound(arr) - 1
If (arr(j) > arr(j + 1)) Then
t = arr(j)
arr(j) = arr(j + 1)
arr(j + 1) = t
End If
Next j
Next i
End Sub

0

LVL 12

Expert Comment

ID: 1470727
Cheat. Put them in a SORTED listbox and read them all out sequentially.

M

0

Author Comment

ID: 1470728
I like the cheat. it's simplier.
0

LVL 13

Expert Comment

ID: 1470729
Yes, Ok in the example I use a listbox. But maybe he wants to just have a sorted array in memory.
0

## Featured Post

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) 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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
###### Suggested Courses
Course of the Month15 days, 8 hours left to enroll