mover un elemento de un array

mover un elemento de un array

Postby goosfancito » Mon Feb 15, 2021 4:54 pm

hola.
Se puede, sin usar ains y luego copiar y luego adel, mover un elemento de un array a otra posicion del mismo arrray?

a[1]:= "a"
a[2]:= "b"
a[3]:= "c"

quedando como resultado final

a[1]:= "a"
a[2]:= "c"
a[3]:= "b"


gracias.
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: mover un elemento de un array

Postby George » Mon Feb 15, 2021 8:59 pm

Dependiendo de lo que quieras hacer y del tamaño del Array tal vez te funcione lo siguiente:

cTmp := a[2]
a[2] := a[3]
a[3] := cTmp
George
 
Posts: 724
Joined: Tue Oct 18, 2005 6:49 pm

Re: mover un elemento de un array

Postby FranciscoA » Tue Feb 16, 2021 2:48 am

Si a lo que te refieres es a inter-cambiar filas, prueba el siguiente codigo.
Code: Select all  Expand view
//----------------------------------------------------//
Function interCambFILA()
   local oDlg, oBrw, oFont, oCur  
   local aData[ 12 ]

   AEval( aData, { |u,i| aData[ i ] := { NtoCMonth(i), i } } )

   DEFINE CURSOR oCur DRAG
   DEFINE FONT oFont NAME "VERDANA" SIZE 0,-16

   DEFINE DIALOG oDlg SIZE 400,300 PIXEL FONT oFont TITLE "DRAG/DROP: INTER-CAMBIAR FILAS"
   @ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
           DATASOURCE aData COLUMNS 1,2 CELL LINES NOBORDER

   WITH OBJECT oBrw
      :nStretchCol      := 1
      :oDragCursor      := oCur
      :bDragBegin       := { |r,c,f,o| SetDropInfo( { oBrw:nArrayAt, oBrw:aRow } ) }
      :bDropOver        := { |u,r,c,f| oBrw:LButtonDown( r,c ), ;
                                       oBrw:LButtonUp(r,c), ;
                                       aData[u[1]] := oBrw:aRow, ;
                                       aData[oBrw:nArrayAt] := u[2], ;
                                       oBrw:Refresh() }

      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED

   RELEASE FONT oFont
   RELEASE CURSOR oCur
return nil

Saludos.
Last edited by FranciscoA on Tue Feb 16, 2021 3:53 pm, edited 1 time in total.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2114
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: mover un elemento de un array

Postby goosfancito » Tue Feb 16, 2021 10:44 am

Hola. No precisamente.

Hoy por hoy tengo este codigo.
Code: Select all  Expand view
  AIns( ::aDatos, nDestino + 1, ::aDatos[ nOrigen ], .T. )
   ADel( ::aDatos, nOrigen + 1, .T. )
 


y queria mejorarlo, pense que habia una funcion interna que podría utilizar.

gracias.
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 54 guests