FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Copia de matrices
Posts: 610
Joined: Wed Oct 19, 2005 08:20 PM
Copia de matrices
Posted: Fri Jul 18, 2014 06: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
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Copia de matrices
Posted: Fri Jul 18, 2014 06: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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Copia de matrices
Posted: Fri Jul 18, 2014 07:26 PM
Quizas esto te pueda ayudar
Code (fw): Select all Collapse
#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
Posts: 610
Joined: Wed Oct 19, 2005 08:20 PM
Re: Copia de matrices
Posted: Fri Jul 18, 2014 08: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
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: Copia de matrices
Posted: Fri Jul 18, 2014 10:21 PM
Esto tambien deberia funcionar

Code (fw): Select all Collapse
#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
Posts: 610
Joined: Wed Oct 19, 2005 08:20 PM
Re: Copia de matrices
Posted: Sat Jul 19, 2014 07: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

Continue the discussion