I have an array witch I pass to a function by reference to sort it. However, seems like the array is passed byval. Can anyone solve what's the problem? (Also sort workarounds accepted)
1) The script below passes an array by-reference to the sort function.
2) Sort function outputs the sorted array values.
3) The script outputs the sorted array values. However they are not sorted.
The script outputs:
300,200,100,,
100,200,300,
'declare variables
mitta(1) = 1
mitta(2) = 2
mitta(3) = 3
sort(mitta) ' see the function below
' show variables
For i = 1 To 3
response.write mitta(i) & ","
next
' sort function
function sort(byref a)
dim num,i,j,temp
num = ubound(a)+1
For i = 0 To num - 1
For j = i + 1 To num - 1
If a(i) < a(j) Then
temp = a(i)
a(i) = a(j)
a(j) = temp
End If
Next
Next
' show sorted variables
For i = 0 To num - 1
response.write a(i) & ","
a(i) = 0
next
end function