# A Very Simple Sort

A very simpile example of sorting. Not the most efficeint, but easy for beginners to see whats happening.

Original Author: Paul Crowdy

### Inputs

Unsorted Array, Sort order (True = Sort Ascending)

Sorted Array

### Code

`Private Sub Form_Load()  Dim a(10)  a(0) = 2  a(1) = 5  a(2) = 7  a(3) = 6  a(4) = 13  a(5) = "b"  a(6) = 65  a(7) = 0  a(8) = 4  a(9) = "a"  a(10) = 1000    Sort a, False    For i = 0 To 10    Debug.Print a(i)  Next iEnd SubSub Sort(ByRef Arr() As Variant, Optional ByVal bAsc As Boolean = True)  Dim Done As Boolean  Done = False  Do While Done = False    Done = True    For i = 0 To UBound(Arr) - 1      If (Arr(i) > Arr(i + 1) And bAsc) Or (Arr(i) < Arr(i + 1) And Not bAsc) Then Swap Arr(i), Arr(i + 1): Done = False    Next i  LoopEnd SubSub Swap(ByRef a As Variant, ByRef b As Variant)  Dim tmp As Variant  tmp = a  a = b  b = tmpEnd Sub`

Posted: 2003-06-01
By: ArchiveBot
Viewed: 99 times

Categories

Visual Basic 6

Attachments

No attachments for this post