Dear friends,
What is the most effective way to copy certain columns from an ARRAY to a new ARRAY:
eg ARRAY {"col1", "col2", "col3", "col4", "col5"}
new ARRAY {"col1", "col3", "col5"}
Best regards,
Otto
Copy ARRAY filtered by column
- Otto
- Posts: 6403
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 24 times
- Been thanked: 2 times
- Contact:
Copy ARRAY filtered by column
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- Otto
- Posts: 6403
- Joined: Fri Oct 07, 2005 7:07 pm
- Has thanked: 24 times
- Been thanked: 2 times
- Contact:
Re: Copy ARRAY filtered by column
Hello friends,
the code is for FIVEWIN and modHarbour.
This is how to use in modHarbour.
Best regards.
Otto
![Image](https://mybergland.com/fwforum/mod_xbrwclip4.jpg)
![Image](https://mybergland.com/fwforum/mod_xbrwclip3.jpg)
the code is for FIVEWIN and modHarbour.
This is how to use in modHarbour.
Best regards.
Otto
![Image](https://mybergland.com/fwforum/mod_xbrwclip4.jpg)
![Image](https://mybergland.com/fwforum/mod_xbrwclip3.jpg)
Code: Select all | Expand
// Copy an array select cols and col sorting
#include "FiveWin.ch"
//----------------------------------------------------------------------------//
function Main()
local aOrg := { {"1col1","col2","col3","col4","1col5","col6","col7","1col8" },;
{"2col1","col2","col3","col4","2col5","col6","col7","2col8" },;
{"3col1","col2","col3","col4","3col5","col6","col7","3col8" }}
local aData := {}
local I := 0
local nIdx := 0
local aCols := {}
local aTmp := {}
local nCol := 0
local hxBrowse := {=>}
hxBrowse["acol"] := {2,1}
if Empty( HGet( hxBrowse, "acol") ) = .F.
aCols := hxBrowse["acol"]
endif
//aCols empty - all cols copied
//ROW
FOR I := 1 to len( aOrg )
if empty(aCols) = .f.
//cols sorting and selecting
aTmp := {}
FOR nIdx := 1 to len( aCols )
nCol := aCols[ nIdx ]
AADD( aTmp, aOrg[ I ][ nCol ] )
NEXT
AADD( aData, EVAL( ArrayGetBlock( aTmp , 1,"test") ) )
else
AADD( aData, EVAL( ArrayGetBlock( aOrg[ I ], 1,"test" ) ) )
endif
NEXT
xbrowse( aData )
return nil
//----------------------------------------------------------------------------//
function ArrayGetBlock( aGets, i, cText )
local aTmp := ACLONE( aGets )
return { | u | aTmp }
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: Copy ARRAY filtered by column
1) Using FWH function ArrayTransposeQ()
a) This is not efficient
b) You do not use FWH functions in modHarbour.
2) AEval
Code: Select all | Expand
aData := .... your array
aNew := ArrTransposeQ( aData )
HB_ADel( aNew, 4, .t. )
HB_ADel( aNew, 2, .t. )
aNew := ArrTranposeQ( aNew )
b) You do not use FWH functions in modHarbour.
2) AEval
Code: Select all | Expand
aNew := {}
AEval( aOriginal, { |a| AAdd( aNew, { a[ 1 ], a[ 3 ], a[ 5 ] } ) } )
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India