by Colin Woor (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating:
(3 Votes)
Simply sorts a 1 dimensional array using a bubble sort algorythm.
Inputs
Array to be sorted
Code Returns
A sorted array
'
'Use:
'
'Sort Array
'
'to sort (A-Z / 1-10, Accending)
'Pretty easy to update it to sort 2 or 3 dimensional arrays
'Or to sort decending
'
'Comments or any info email: [email protected]
'
Public Sub sort(tmparray)
Dim SortedArray As Boolean
Dim start, Finish As Integer
SortedArray = True
start = LBound(tmparray)
Finish = UBound(tmparray)
Do
SortedArray = True
For loopcount = start To Finish - 1
If tmparray(loopcount) > tmparray(loopcount + 1) Then
SortedArray = False
Call swap(tmparray, loopcount, loopcount + 1)
End If
Next loopcount
Loop Until SortedArray = True
End Sub
Sub swap(swparray, fpos, spos)
Dim temp As Variant
temp = swparray(fpos)
swparray(fpos) = swparray(spos)
swparray(spos) = temp
End Sub