this seems to work...

Code:
$previousstate = SetOption( "NoVarsInStrings", "ON" )

dim $A[9]
$A[0] = 1
$A[1] = 7
$A[2] = 3
$A[3] = 4
$A[4] = 5
$A[5] = 5
$A[6] = 7
$A[7] = 2
$A[8] = 1
$A[9] = 1

$sorted = qs($A)

for each $x in $sorted
? $x
next
?
$UniqueArray = GetFirstFiveUnique($A)
for each $x in $UniqueArray
? $x
next


$answer = FindIndexes($A, $UniqueArray)
for $x=0 to ubound($answer,1)
? "Value of " + $answer[$x,0]
? "Is at these indexes: "
for each $index in $answer[$x,1]
" " + $index
next
?
next


function GetFirstFiveUnique($Array)
dim $i, $x, $y, $sorted, $Result[0]

$sorted = qs($Array)
$x = 0
for $i=0 to ubound($sorted)
if $i=0
$Result[0] = $sorted[0]
$x = 1 + $x
endif
if $i > 0
if $Result[$x-1] <> $sorted[$i]
Redim Preserve $Result[$x]
$Result[$x] = $sorted[$i]
$x = 1 + $x
endif
endif
if $x = 5
$i = 1 + ubound($Array)
endif
next
$GetFirstFiveUnique = $Result

endfunction


function FindIndexes ($OrigArray, $ArrayOfFive)
dim $results[4,1], $x, $y, $z

for $z=0 to ubound($ArrayOfFive)

dim $ElementIndex[0]
$y=0
for $x=0 to ubound($OrigArray)
if $ArrayOfFive[$z] = $OrigArray[$x]
Redim Preserve $ElementIndex[$y]
$ElementIndex[$y] = $x
$y = 1 + $y
endif
next
$results[$z, 0] = $ArrayOfFive[$z]
$results[$z, 1] = $ElementIndex
$FindIndexes = $results
next
endfunction


function qs($a)
DIM $b[32],$c[32],$d,$e,$f,$g,$h,$i,$j,$k,$l
$b[0]=0
$c[0]=UBOUND($a)
$d=0
While $d >=0
$e=$b[$d]
$f=$c[$d]
While $e < $f
$h=$e+($f-$e)/2
$k=$a[$e]
$A[$e]=$A[$h]
$A[$h]=$k
$i=$e+1
$j=$f
$l=0
Do
While ($i<$j) AND $A[$e] > $A[$i]
$i=$i+1
Loop
While ($j>=$i) AND $A[$j] > $A[$e]
$j=$j-1
Loop
IF $i>=$j
$l=1
ELSE
$k=$A[$i]
$A[$i]=$A[$j]
$A[$j]=$k
$j=$j-1
$i=$i+1
ENDIF
Until $l=1
$k=$a[$e]
$a[$e]=$a[$j]
$a[$j]=$k
$g=$j
If $g-$e <= $f - $g
If $g+1 < $f
$b[$d]=$g+1
$c[$d]=$f
$d=$d+1
Endif
$f=$g-1
Else
If $g-1 > $e
$b[$d]=$e
$c[$d]=$g-1
$d=$d+1
Endif
$e=$g+1
Endif
Loop
$d=$d-1
Loop
$qs=$a
Endfunction

_________________________
Home page: http://www.kixhelp.com/hb/