Domino Code Fragment

Code Name*
AlphaQuickSort function which sorts the elements in the array.
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.3.144.98.13
Description*
This example asks the user for input of names and assigns each name to an element in the array. On NULL input it calls the AlphaQuickSort function which sorts the elements in the array.
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:
Usage

The valid values for the arayelts elements are alphanumeric characters. This will not sort an array of strictly numeric elements. Assign the return to a variant variable.

Example

This example asks the user for input of names and assigns each name to an element in the array. On NULL input it calls the AlphaQuickSort function which sorts the elements in the array. The return is assigned to a variable of type variant. The sorted elements are then formatted for display in Messagebox.

AlphaQuickSort Function

Function AlphaQuickSort (nFirst As Integer, nLast As Integer, arrayelts As Variant) As Variant

Sorts an array of alphanumeric elements. The function returns an array of the elements sorted alphanumerically.

Function Syntax

AlphaQuickSort( nFirst , nLast , arrayelts )

Formal Parameters

nFirst

Must be an integer variable of the Lower Bound of the Array to be sorted.

nLast

Must be an integer variable of the Upper Bound of the Array to be sorted.

arrayelts

Pass the Array that will be sorted.

Return value

The AlphaQuickSort function's return value is an array. This array will contain the elements of arrayelts sorted alphanumerically.

You must assign the return to a variant variable.

Function

'-- nFirst is the LowerBound of arrayelts, nLast is the Upper Bound of arrayelts, arrayelts is the
'-- alphanumeric array to be sorted. Return value is arrayelts sorted alphanumerically.
Function
AlphaQuickSort(nFirst As Integer, nLast As Integer, arrayelts As Variant) As Variant
Dim m As Variant
Dim i As Integer '-- Stores the Lower bound for tracking
Dim t As Variant '-- Used to store temp value
Dim j As Integer '-- Stores the Upper bound for tracking
If nLast > nFirst Then '-- If there's nothing to sort, jump out
m = arrayelts(nFirst) '-- Initialize boundaries, nominate a value to sort
j = nLast
i = nFirst

'-- Repeat until i and j "meet in the middle"
While (i < j)

'-- Push in the boundaries while data is sorted
While (arrayelts(i) <= m And i < nLast)
i = i + 1
Wend
While (arrayelts(j) > m)
j = j - 1
Wend

'-- If there is data between i and j something is out of order - swap it
If i < j Then

t = arrayelts(i)
arrayelts(i) = arrayelts(j)
arrayelts(j) = t
End If
Wend

t = arrayelts(nFirst)
'-- Swap the nominated and bottom values - why we came here
arrayelts(nFirst) = arrayelts(j)
arrayelts(j) = t

'-- Recurse and sort data either side of upper bound
Call AlphaQuicksort (nFirst, j - 1, arrayelts)
Call AlphaQuicksort ((j + 1), nLast, arrayelts)
AlphaQuicksort = arrayelts
End If
End Function