Reputation: 3472
On trying to pass the double array to a bubble sort sub i get the error message: "Type mismatch: array or user-defined type expected"
If i change the array from Variant to double inside the sub i get rid of the error; however i need to use the same sub for sorting int, double and user defined arrays. I tried using function but no luck. Using Excel 2003 on Windows7.
Sub BubbleSort(MyArray() As Variant)
Dim i As Long, j As Long
Dim Temp As Variant
For i = LBound(MyArray) To UBound(MyArray) - 1
For j = i + 1 To UBound(MyArray)
If MyArray(i) > MyArray(j) Then
Temp = MyArray(j)
MyArray(j) = MyArray(i)
MyArray(i) = Temp
End If
Next j
Next i
End Sub
Public Sub Main()
Dim tempArr() As Double
For i = 0 To 10
ReDim Preserve tempArr(i)
tempArr(i) = i * i
Next i
Call BubbleSort(tempArr) 'Error pops up here
End Sub
Upvotes: 0
Views: 60