Solved

Sorting variables in array

Posted on 1999-01-26
4
203 Views
Last Modified: 2010-05-03
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
Comment
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
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Accepted Solution

by:
Mirkwood earned 50 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
        List1.AddItem Str(arr(i))
    Next
End Sub

Private Sub Form_Load()
    Dim i As Integer
    For i = 0 To 6
        arr(i) = Rnd() * 100
        List1.AddItem Str(arr(i))
    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

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

M

0
 

Author Comment

by:timothy1
ID: 1470728
I like the cheat. it's simplier.
0
 
LVL 13

Expert Comment

by:Mirkwood
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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 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…

730 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