Solved

Sorting variables in array

Posted on 1999-01-26
4
210 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…

717 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