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  
 
 [ 2 post ] 

 Relevant Pages 

1. Accessing Access 2.0 database with VB3, ODBC 2.0 and Microsotf Jet Engine Compatibility Layer

2. Install Access 2.0 Cmpt Layer w/o Access 2.0 for VB 3.0

3. VB control arrays in MS Access 2.0

4. VB control arrays in MS Access 2.0

5. Access 97: Sorting Arrays

6. Looking for an algorithm for building an index-array for sorting an array or database table

7. VB 4.0, Access 2.0, or VC++ 2.0?

8. Can't Install 2.0 compatibility layer without Access 2.0

9. MS Access 2.0/MS Jet 2.0 Locks

10. VB 3.0, Access 2.0 and Crystal Reports 2.0

11. VB 4.0, Access 2.0, or VC++ 2.0?

12. VB 2.0 and Access 1.0 / 2.0 Problem.

 

 
Powered by phpBB® Forum Software