|
-
Sep 25th, 2000, 03:09 PM
#12
Hello guys,
This code works well, except for 1 minor thing,
maxPercentage should be initialized to sortedArray(x) instead of 0.
0 works fine for descending order, but will not work for ascending. Also first For.. Next loop is not needed as sort can be done on incoming array, don't really need output array.
Private Sub sortArray(incomingArray() As stuff, sortedArray() As stuff)
For x = LBound(sortedArray) To UBound(sortedArray)
sortedArray(x) = incomingArray(x)
Next x
Dim max As Integer
Dim maxPercentage As Integer
Dim temp As stuff
For x = 1 To UBound(sortedArray)
max = x
maxPercentage = 0
For y = x To UBound(sortedArray)
With sortedArray(y)
'If Int((.aMinVal / .aMaxVal) * 100) < maxPercentage Then 'for ascending order use this line
If Int((.aMinVal / .aMaxVal) * 100) > maxPercentage Then 'for descending order use this line
maxPercentage = Int((.aMinVal / .aMaxVal) * 100)
max = y
End If
End With
Next y
'swap
temp = sortedArray(max)
sortedArray(max) = sortedArray(x)
sortedArray(x) = temp
Next x
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|