I made a little function that finds the largest or smallest value position in an existing array.
For the value parameter either enter the string "smallest" or "largest" (No capitals) to find that position in the array.
Hope someone finds this usefull.
Function:
Function ArrayValueFinder(TotalValuesToSort,Value$)
Total=TotalValuesToSort
dim Array(Total+1)
For X=1 to Total
Array(X)= //Insert the array you want to find the smallest/largest value position of
NEXT X
dim ArrayOrg(Total+1)
For X=1 to Total
ArrayOrg(X)=Array(X)
NEXT X
if Value$="smallest"
For Redo=1 to Total+(Total-1)
For X=1 to Total
If (X+1)<Total+1
If Array(X)>Array(X+1)
Temp=Array(X+1)
Array(X+1)=Array(X)
Array(X)=Temp
endif
endif
NEXT X
NEXT Redo
endif
if Value$="largest"
For Redo=1 to Total+(Total-1)
For X=1 to Total
If (X+1)<Total+1
If Array(X)<Array(X+1)
Temp=Array(X+1)
Array(X+1)=Array(X)
Array(X)=Temp
endif
endif
NEXT X
NEXT Redo
endif
For X=1 to Total
If ArrayOrg(X)=Array(1) then ArrayPos=X
Next X
endfunction ArrayPos
Demo:
Dim MyArray(5)
MyArray(1)=4
MyArray(2)=9
MyArray(3)=2
MyArray(4)=11
MyArray(5)=15
print "Smallest value is in array position ";ArrayValueFinder(5,"smallest")
print "Largest value is in array position ";ArrayValueFinder(5,"largest")
wait key
end
Function ArrayValueFinder(TotalValuesToSort,Value$)
Total=TotalValuesToSort
dim Array(Total+1)
For X=1 to Total
Array(X)= MyArray(X)
NEXT X
dim ArrayOrg(Total+1)
For X=1 to Total
ArrayOrg(X)=Array(X)
NEXT X
if Value$="smallest"
For Redo=1 to Total+(Total-1)
For X=1 to Total
If (X+1)<Total+1
If Array(X)>Array(X+1)
Temp=Array(X+1)
Array(X+1)=Array(X)
Array(X)=Temp
endif
endif
NEXT X
NEXT Redo
endif
if Value$="largest"
For Redo=1 to Total+(Total-1)
For X=1 to Total
If (X+1)<Total+1
If Array(X)<Array(X+1)
Temp=Array(X+1)
Array(X+1)=Array(X)
Array(X)=Temp
endif
endif
NEXT X
NEXT Redo
endif
For X=1 to Total
If ArrayOrg(X)=Array(1) then ArrayPos=X
Next X
endfunction ArrayPos
If it hasn't exploded yet, I haven't touched it.