I am trying to sort the elements of a field manually without using any built in function. Below is my code

```
    Function Test(myval As Variant) As Variant
        Dim rst As DAO.Recordset
        Dim arr() As Double
        Dim arr_lenght As Long
        Dim i As Integer
        Dim j As Integer
        Dim k As Integer
        Dim temp As Double
        Dim count As Integer
        Dim Index As Integer

        Set rst = CurrentDb.OpenRecordset("SELECT [Salary (t) Total] FROM SalaryT")

        count = 1
        Index = 0
        rst.MoveFirst

        Do While Not rst.EOF
            On Error Resume Next
            arr(count) = CDbl(rst![Salary (t) Total])
            count = count + 1
            rst.MoveNext
        Loop

        arr_length = UBound(arr) - 1

'This is my sorting algorithm

        For i = 1 To arr_length
            For j = (i + 1) To arr_length
                   If arr(i) < arr(j) Then
                    temp = arr(i)
                    arr(i) = arr(j)
                    arr(j) = temp
                   End If
            Next j
        Next i

        For k = LBound(arr) To UBound(arr)
            If arr(k) = CDbl(myval ) Then
                Index = k
                Exit For
            End If
        Next k

        Test = Index     
    End Function

```

This always output 0 since I set the Index at the beginning 0. But in the last for loop I change the Index value with the value of K and it looks like it is not changing the value. What is wrong with this code. Please help me to fix it. Thanks.

Some example data from SalaryT:

```
ID  Name           Salary (t) Total 
1   test name1       55,234.30
2   test name2       2,322.29 

```

Salary (t) Total save the values as text. And later in arr array I take those values and keep them as Double value.

myval send a value from Salary (t) Total column. So some example function call could be

```
Test(55,234.30)
Test(2,322.29)

```