Copia de matrices

Copia de matrices

Postby Manuel Aranda » Fri Jul 18, 2014 6:03 pm

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?
Un saludo,
Manuel

xH 1.2.3, FWH 23.07 32 bits, BC++ 7.4, xVerce CW 1.0, PellesC
User avatar
Manuel Aranda
 
Posts: 603
Joined: Wed Oct 19, 2005 8:20 pm
Location: España

Re: Copia de matrices

Postby hmpaquito » Fri Jul 18, 2014 6:30 pm

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
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Copia de matrices

Postby cnavarro » Fri Jul 18, 2014 7:26 pm

Quizas esto te pueda ayudar
Code: Select all  Expand view

#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

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Copia de matrices

Postby Manuel Aranda » Fri Jul 18, 2014 8:33 pm

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.
Un saludo,
Manuel

xH 1.2.3, FWH 23.07 32 bits, BC++ 7.4, xVerce CW 1.0, PellesC
User avatar
Manuel Aranda
 
Posts: 603
Joined: Wed Oct 19, 2005 8:20 pm
Location: España

Re: Copia de matrices

Postby cnavarro » Fri Jul 18, 2014 10:21 pm

Esto tambien deberia funcionar

Code: Select all  Expand view

#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

 
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6504
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: Copia de matrices

Postby Manuel Aranda » Sat Jul 19, 2014 7:09 am

Cierto, también funciona correctamente. Gracias de nuevo, Cristobal.
Un saludo,
Manuel

xH 1.2.3, FWH 23.07 32 bits, BC++ 7.4, xVerce CW 1.0, PellesC
User avatar
Manuel Aranda
 
Posts: 603
Joined: Wed Oct 19, 2005 8:20 pm
Location: España


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], Jorge Jaurena and 46 guests