"Variable uses an Automation type not supported in Visual Basic" withFilter Function??



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
For i = 1 To UBound(ArrayList)

If i = 1 Then
WinningVal = ArrayList(i)
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
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
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


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads