Bubble Sort - Text List Alphabetical Sort

Mindwatering Incorporated

Author: Tripp W Black

Created: 07/26/2000 at 11:31 PM

 

Category:
Notes Developer Tips
Forms/Subforms, LotusScript

A bubble-sort LotusScript function. Function was used with a string based array variant passed.
(This ascending alphanumeric sort uses a simple < / > test. The sorting may not work as expected for special characters and double byte character sets. )

Function SortList (srcLst As Variant) As Variant
' sorts incoming list
Dim top As Integer
Dim bottom As Integer
Dim CurrentItem As Integer
Dim NextItem As Integer
Dim tmpVar As Variant ' temp variable to hold current value being moved in list

If Not (Isarray(srcLst)) Then
' not a list, return original value
SortList = srcLst
End If

top=Ubound (srcLst)
Bottom=Lbound (srcLst)

For CurrentItem=bottom To top
NextItem = CurrentItem
Do While NextItem > Bottom
If (srcLst(NextItem) > srcLst(NextItem-1)) Then
Exit Do
Else
tmpVar=srcLst(NextItem)
srcLst(NextItem)=srcLst(NextItem-1)
srcLst(NextItem-1)=tmpVar
End If
NextItem=NextItem-1
Loop
Next
SortList = srcLst
End Function

previous page