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 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 }
aData := .... your array
aNew := ArrTransposeQ( aData )
HB_ADel( aNew, 4, .t. )
HB_ADel( aNew, 2, .t. )
aNew := ArrTranposeQ( aNew )
aNew := {}
AEval( aOriginal, { |a| AAdd( aNew, { a[ 1 ], a[ 3 ], a[ 5 ] } ) } )
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 93 guests