Page 1 of 1
Copia de matrices
Posted: Fri Jul 18, 2014 6:03 pm
by Manuel Aranda
Necesito copiar el contenido de dos matrices en una sola.
Tengo este código pero creo estar haciendo algo mal puesto que se pierden algunos valores:
cDir += "\*.db*"
cDir2 += "\*.rtf"
aFiles := Directory( cDir,,, XBL_FILEWITHPATH )
aFiles2:= Directory( cDir2,,, XBL_FILEWITHPATH )
aCOPY(aFiles2,aFiles)
Podeis ayudarme?
Re: Copia de matrices
Posted: Fri Jul 18, 2014 6:30 pm
by hmpaquito
Manuel,
El aCopy() no hace lo que tu esperas que haga. El aCopy() copia sobre el destino y NO añade.
Hazte una función aInsertar(). En las "viejas" funciones Clipper no hay nada que haga lo que tu quieres. Tendrias que utilizar el Aadd(). En (x)Harbour no sé si habrá alguna función que haga eso.
[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
ACOPY()
Copy elements from one array to another
------------------------------------------------------------------------------
Syntax
ACOPY(<aSource>, <aTarget>,
[<nStart>], [<nCount>], [<nTargetPos>]) --> aTarget
Arguments
<aSource> is the array to copy elements from.
<aTarget> is the array to copy elements to.
<nStart> is the starting element position in the <aSource> array.
If not specified, the default value is one.
<nCount> is the number of elements to copy from the <aSource> array
beginning at the <nStart> position. If <nCount> is not specified, all
elements in <aSource> beginning with the starting element are copied.
<nTargetPos> is the starting element position in the <aTarget> array
to receive elements from <aSource>. If not specified, the default value
is one.
Returns
ACOPY() returns a reference to the target array, <aTarget>.
Description
ACOPY() is an array function that copies elements from the <aSource>
array to the <aTarget> array. The <aTarget> array must already exist
and be large enough to hold the copied elements. If the <aSource> array
has more elements, some elements will not be copied.
ACOPY() copies values of all data types including NIL and code blocks.
If an element of the <aSource> array is a subarray, the corresponding
element in the <aTarget> array will contain a reference to the subarray.
Thus, ACOPY() will not create a complete duplicate of a multidimensional
array. To do this, use the ACLONE() function.
Examples
. This example creates two arrays, each filled with a value.
The first two elements from the source array are then copied into the
target array:
LOCAL nCount := 2, nStart := 1, aOne, aTwo
aOne := { 1, 1, 1 }
aTwo := { 2, 2, 2 }
ACOPY(aOne, aTwo, nStart, nCount)
// Result: aTwo is now { 1, 1, 2 }
Files Library is CLIPPER.LIB.
See Also: ACLONE() ADEL() AEVAL() AFILL() AINS() ASORT()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson
Saludos
Re: Copia de matrices
Posted: Fri Jul 18, 2014 7:26 pm
by cnavarro
Quizas esto te pueda ayudar
Code: Select all
#include "Fivewin.ch"
Function Main()
Local x
Local cDir := ".\*.db*"
Local cDir2 := ".\*.prg"
Local aFiles := Directory( cDir,,, )
Local aFiles2 := Directory( cDir2,,, )
? Len( aFiles ), Len( aFiles2 )
For x = 1 to Len( aFiles2 )
AAdd( aFiles, aFiles2[x] )
Next x
? Len( aFiles )
Return nil
Re: Copia de matrices
Posted: Fri Jul 18, 2014 8:33 pm
by Manuel Aranda
Muchas gracias a los dos, hmpaquito, efectivamente no estaba utilizando correctamente aCopy.
Cristobal, muy agradecido, no había caído en cuenta en hacerlo como indicas. Funciona perfectamente.
Re: Copia de matrices
Posted: Fri Jul 18, 2014 10:21 pm
by cnavarro
Esto tambien deberia funcionar
Code: Select all
#include "Fivewin.ch"
Function Main()
Local cDir := ".\*.db*"
Local cDir2 := ".\*.prg"
Local aFiles := Directory( cDir,,, )
Local aFiles2 := Directory( cDir2,,, )
? Len( aFiles ), Len( aFiles2 )
AEval( aFiles2, { | aT, nEle | AAdd( aFiles, aT ) } )
? Len( aFiles )
Return nil
Re: Copia de matrices
Posted: Sat Jul 19, 2014 7:09 am
by Manuel Aranda
Cierto, también funciona correctamente. Gracias de nuevo, Cristobal.