hjælp til asp komponent - sortering af array
Jeg har en sub til sort af et array.For at få en bedre ydelse kunne jeg godt tænke mig at få der ovet i et komponent.
Men... jeg er næsten helt ny med selv at lave komponenter, Har prøvet at lave klassikkeren 'hello world' ;-)
Sub:
Private Sub SortResultsByNumMatches(ByRef sarySearchResults, ByRef intTotalFilesFound)
'Dimension variables
Dim intArrayGap 'Holds the part of the array being sorted
Dim intIndexPosition 'Holds the Array index position being sorted
Dim intTempResultsHold 'Temperary hold for the results if they need swapping array positions
Dim intTempNumMatchesHold 'Temperary hold for the number of matches for the result if they need swapping array positions
Dim intPassNumber 'Holds the pass number for the sort
'Loop round to sort each result found
For intPassNumber = 1 To intTotalFilesFound
'Shortens the number of passes
For intIndexPosition = 1 To (intTotalFilesFound - intPassNumber)
'If the Result being sorted hass less matches than the next result in the array then swap them
If sarySearchResults(intIndexPosition,2) < sarySearchResults((intIndexPosition+1),2) Then
'Place the Result being sorted in a temporary variable
intTempResultsHold = sarySearchResults(intIndexPosition,1)
'Place the Number of Matches for the result being sorted in a temporary variable
intTempNumMatchesHold = sarySearchResults(intIndexPosition,2)
'Do the array position swap
'Move the next Result with a higher match rate into the present array location
sarySearchResults(intIndexPosition,1) = sarySearchResults((intIndexPosition+1),1)
'Move the next Number of Matches for the result with a higher match rate into the present array location
sarySearchResults(intIndexPosition,2) = sarySearchResults((intIndexPosition+1),2)
'Move the Result from the teporary holding variable into the next array position
sarySearchResults((intIndexPosition+1),1) = intTempResultsHold
'Move the Number of Matches for the result from the teporary holding variable into the next array position
sarySearchResults((intIndexPosition+1),2) = intTempNumMatchesHold
End If
Next
Next
End Sub
