Sorting an array in Access 2.0
Author Message
Sorting an array in Access 2.0

I have a problem sorting elements in an array in Access 2.0. Is there an
easy way to do this?

Mon, 25 Oct 1999 03:00:00 GMT
Sorting an array in Access 2.0

Quote:
>I have a problem sorting elements in an array in Access 2.0. Is there an
>easy way to do this?

You need to write a sort routine such as a bubble sort, or a
QuickSort. This example is from Total Access SourceBook
(http://www.fmsinc.com/products/SourceBook/index.html)

Function QuickSortIntegerArray_TSB(arrIn() As Integer, ByVal
intLowBound As Integer, ByVal intHighBound As Integer) As Integer
' Comments   : Sort the passed array (quicksort algorithm)
' Parameters : arrIn() - array of integer
'              intLowBounds - low bound of array
'              intHighBound - high bound of array
' Returns    : True if successful, False otherwise
'
Dim intMidBound As Integer
Dim intX As Integer
Dim intY As Integer
Dim intTmp As Integer
Dim fOK As Integer

On Error GoTo PROC_ERR

If intHighBound > intLowBound Then

intMidBound = arrIn((intLowBound + intHighBound) \ 2)
intX = intLowBound
intY = intHighBound

Do While intX <= intY

If arrIn(intX) >= intMidBound And arrIn(intY) <= intMidBound
Then
intTmp = arrIn(intX)
arrIn(intX) = arrIn(intY)
arrIn(intY) = intTmp
intX = intX + 1
intY = intY - 1
Else
If arrIn(intX) < intMidBound Then
intX = intX + 1
End If
If arrIn(intY) > intMidBound Then
intY = intY - 1
End If
End If

Loop

fOK = QuickSortIntegerArray_TSB(arrIn(), intLowBound, intY)
fOK = QuickSortIntegerArray_TSB(arrIn(), intX, intHighBound)

End If

QuickSortIntegerArray_TSB = True

PROC_EXIT:
Exit Function

PROC_ERR:
QuickSortIntegerArray_TSB = False
Resume PROC_EXIT

End Function

-- Jim Ferguson, FMS
http://www.fmsinc.com

Mon, 25 Oct 1999 03:00:00 GMT

 Page 1 of 1 [ 2 post ]

Relevant Pages