Código fuente de 'Ordena array 2.asp'

<title>Ordena array 2 - Códigos asp, programacion asp, descargas asp, rutinas asp</title>
<p align="center"><b><font size="3">Ordena array 2</font></b>
<body style="font-family: Arial; font-size: 11pt"></p>

    ' Name: Multidimensional Array Sort function in VB Script
    ' Description:This function will sort an array. 
    Currently it keys in on the first column of the array(0,?). It will reorder all the information 
    in each row of the array so that the fist column of the array is sorted. The first column is compar
    ed using a string compare function.
    I use this In many of my sites where I have To pull back encrypted data from the database. 
    I decrypt the data With a Active X object inside of the ASP script Then place all the data into 
    an array. Once the data is in the array I can sort it and display it to the user.
    Future enhancements To this function will include the ability to Select which column of the array you 
    would like to sort on.
    ' By: Eric Repec InetSolution

    ' Assumes:Currently it keys in on the first column of the array(0,?).
    ' Side Effects:None.
    'http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6482&lngWId=4    'for details.    
    function OrdenaVector(values())
    Dim i 
    Dim j 
    Dim smallest_value 
    Dim smallest_j 
    Dim min
    Dim max
    Dim temp
    min = lbound(values,2)
    max = ubound(values,2)
    	For i = min To max - 1
    	smallest_value = values(0,i)
    	smallest_j = i
    	For j = i + 1 To max
    		' See if values(j) is smaller. changed To strComp to work With strings.
    		if strComp(values(0,j),smallest_value,vbTextCompare) = -1 Then
    			' Save the new smallest value.
    			smallest_value = values(0,j)
    			smallest_j = j
    		End if
    		Next 'j
    		if smallest_j <> i Then
    			' Swap items i and smallest_j.
    			For intA = 0 To ubound(values,1)
    				temp = values(intA,smallest_j)
    				values(intA,smallest_j) = values(intA,i)
    				values(intA,i) = temp
    			Next 'intA
    		End if
    	Next 'i
    OrdenaVector = values
    End function

    Dim aUnSort(2,2), aSorted
    aUnSort(0,0) = 9
    aUnSort(0,1) = 8
    aUnSort(0,2) = 7
    aUnSort(1,0) = 6
    aUnSort(1,1) = 5
    aUnSort(1,2) = 4
    aUnSort(2,0) = 3
    aUnSort(2,1) = 2
    aUnSort(2,2) = 1

    aSorted = OrdenaVector(aUnSort)
    response.write "<b>Valores del array original (vector 3x3): </b>9,8,7,6,5,4,3,2,1<br>"
    Response.write "<b>Valores ordenados por filas: </b>"
    For i = 0 To 2
    	For j = 0 To 2	        
    	response.write asorted(i,j)
    	if not (j=2 and i=2) then response.write ","