FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour 驴C贸m se ordena un array?
Posts: 234
Joined: Tue Oct 25, 2005 12:39 AM
驴C贸m se ordena un array?
Posted: Wed Oct 26, 2005 03:45 PM

Tengo el siguiente c贸digo que me ordena por el primer elemento, luego por el segundo.

aResumen := ASort( aResumen, , , { | x, y | If( x[1] < y[1], .T., If( x[1] == y[1], x[2] < y[2], FALSE ) ) } )

Pero no he conseguido ordenar por el tercer elemento

Saludos
Fernando Leal
M茅xico, DF

Posts: 108
Joined: Sun Oct 09, 2005 06:12 PM
驴C贸m se ordena un array?
Posted: Thu Oct 27, 2005 01:08 AM

Fernando:

           Que tipo de informacion contiene el array, valores simples o son arrays anidados ?.

Saludos,

Daniel Puente
Mar del Plata, Argentina
danielpuente@speedy.com.ar
puenteda@hotmail.com
Posts: 234
Joined: Tue Oct 25, 2005 12:39 AM
驴C贸m se ordena un array?
Posted: Thu Oct 27, 2005 03:07 AM

Contiene valores simples.

Gracias
Fernando Leal

Posts: 108
Joined: Sun Oct 09, 2005 06:12 PM
驴C贸m se ordena un array?
Posted: Thu Oct 27, 2005 12:43 PM

Fernando:

           Si contiene valores simples no necesitas pasarle el criterio de ordenacion como parametro por cada uno de los elementos. Con poner:

    aMatriz := { 3, 5, 1, 2, 4 }
    ASORT(aMatriz)
    //Resultado: { 1, 2, 3, 4, 5 }

    ASORT(aMatriz,,, { |x, y| x &gt; y })
    //Resultado: { 5, 4, 3, 2, 1 }

           Es suficiente, fijate en las NG.

Saludos,

Daniel Puente
Mar del Plata, Argentina
danielpuente@speedy.com.ar
puenteda@hotmail.com
Posts: 234
Joined: Tue Oct 25, 2005 12:39 AM
驴C贸m se ordena un array?
Posted: Thu Oct 27, 2005 03:51 PM

Daniel,
Perdona... es as铆 como se contruye el array.

while HISTORIA->( !eof() )
AADD( aResumen,{ HISTORIA->CLAVE_VERI, HISTORIA->CPRODUCTO, HISTORIA->ID_VERIF, HISTORIA->ID_ZONA, 1 } )
HISTORIA->( DbSkip() )
enddo

Como ves, recorro la HISTORIA.DBF y voy agregando al array 4 campos y el al quinto solo le pongo el n煤mero 1

Pues, necesito ordenar por CLAVE_VERI despues por CPRODUCTO hasta aqu铆 no tengo problemas, pero no he podido subordernar por ID_VERIF Y ID_ZONA

Saludos
Fernando

Posts: 108
Joined: Sun Oct 09, 2005 06:12 PM
驴C贸m se ordena un array?
Posted: Fri Oct 28, 2005 01:35 AM

Fernando:

aResumen:=ASORT(aResumen,,,{ |x,y| x[1]+x[2]+x[3]+x[4] < y[1]+y[2]+y[3]+y[4] } )

Saludos,

Daniel Puente
Mar del Plata, Argentina
danielpuente@speedy.com.ar
puenteda@hotmail.com
Posts: 234
Joined: Tue Oct 25, 2005 12:39 AM
Re: 驴C贸m se ordena un array?
Posted: Sat Oct 29, 2005 04:46 PM

Funciona bien,
gracias

Saludos
Fernando Leal
M茅xico, DF

Continue the discussion