J
JR
I'm trying to resort an array in ascending order and I'm attempting to
use the filter function to remove the minimum value found for each
iteration through all elements of the array.
all of the values of the array make up the outer loop.
the inner loop consists of all of the elements minus the previous
winning minimum value.
If I randomly generate numbers for a test array and then pass it to
the sorting function, it works fine. However when I pass the actual
array that I need to sort--an array of absolute position integers from
a recordset, it bombs at the filter function :
"458 Variable uses an Automation type not supported in Visual
Basic" is returned
the sorting function:
Function orderArray(ArrayList)
Dim i As Integer
Dim j As Integer
Dim WinningVal
Dim outArray() As Variant
On Error GoTo er:
ReDim outArray(UBound(ArrayList) + 1)
'loop throgh elements, element values in outer loop
'incons, just serve as placeholders
For j = 1 To UBound(ArrayList)
'go through each remaining element and determine the lowest
element
For i = 1 To UBound(ArrayList)
If i = 1 Then
WinningVal = ArrayList(i)
Else
If ArrayList(i) < WinningVal Then
WinningVal = ArrayList(i)
End If
End If
Next i
'set the element of the output array to the winning value this
iteration
outArray(j) = WinningVal
'remove the the winning element from the set
ArrayList = Filter(ArrayList, CStr(WinningVal), False)
'convert set back to number
For i = 1 To UBound(ArrayList)
ArrayList(i) = CSng(ArrayList(i))
Next i
Next j
orderArray = outArray
er:
Debug.Print Err.Number, Err.Description
Resume Next
End Function
_______________________________
'Test random number array generator
Function populateTestarray()
Dim arrayTest()
Dim i As Integer
For i = 1 To 20
ReDim Preserve arrayTest(i)
arrayTest(i) = Rnd * 100
Debug.Print arrayTest(i)
Next i
populateTestarray = arrayTest
End Function
_______________________________________
'sub to run test
Sub sortArrayTest()
Dim LocalArray()
Dim i As Integer
ReDim LocalArray(UBound(populateTestarray))
LocalArray = orderArray(populateTestarray)
For i = LBound(LocalArray) To UBound(LocalArray)
Debug.Print LocalArray(i)
Next i
End Sub
use the filter function to remove the minimum value found for each
iteration through all elements of the array.
all of the values of the array make up the outer loop.
the inner loop consists of all of the elements minus the previous
winning minimum value.
If I randomly generate numbers for a test array and then pass it to
the sorting function, it works fine. However when I pass the actual
array that I need to sort--an array of absolute position integers from
a recordset, it bombs at the filter function :
"458 Variable uses an Automation type not supported in Visual
Basic" is returned
the sorting function:
Function orderArray(ArrayList)
Dim i As Integer
Dim j As Integer
Dim WinningVal
Dim outArray() As Variant
On Error GoTo er:
ReDim outArray(UBound(ArrayList) + 1)
'loop throgh elements, element values in outer loop
'incons, just serve as placeholders
For j = 1 To UBound(ArrayList)
'go through each remaining element and determine the lowest
element
For i = 1 To UBound(ArrayList)
If i = 1 Then
WinningVal = ArrayList(i)
Else
If ArrayList(i) < WinningVal Then
WinningVal = ArrayList(i)
End If
End If
Next i
'set the element of the output array to the winning value this
iteration
outArray(j) = WinningVal
'remove the the winning element from the set
ArrayList = Filter(ArrayList, CStr(WinningVal), False)
'convert set back to number
For i = 1 To UBound(ArrayList)
ArrayList(i) = CSng(ArrayList(i))
Next i
Next j
orderArray = outArray
er:
Debug.Print Err.Number, Err.Description
Resume Next
End Function
_______________________________
'Test random number array generator
Function populateTestarray()
Dim arrayTest()
Dim i As Integer
For i = 1 To 20
ReDim Preserve arrayTest(i)
arrayTest(i) = Rnd * 100
Debug.Print arrayTest(i)
Next i
populateTestarray = arrayTest
End Function
_______________________________________
'sub to run test
Sub sortArrayTest()
Dim LocalArray()
Dim i As Integer
ReDim LocalArray(UBound(populateTestarray))
LocalArray = orderArray(populateTestarray)
For i = LBound(LocalArray) To UBound(LocalArray)
Debug.Print LocalArray(i)
Next i
End Sub