ARRAY

Post Reply
User avatar
MdaSolution
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

ARRAY

Post by MdaSolution »

how I can del an element of a array and refresh the array ?
I have a array aData sample
56,.t.
102,.f.
103,.f.
I want delete only the array element with .t. and refresh the array aData
FWH .. BC582.. xharbour
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: ARRAY

Post by ukoenig »

// I want delete only the array element with .t. and refresh the array aData

PRIVATE aData[5][2]
aData[1] := { 56, .T. }
aData[2] := { 102, .F. }
aData[3] := { 103, .F. }
aData[4] := { 104, .T. }
aData[5] := { 105, .F. }

// Optional
PRIVATE aNEWARRAY := {}


// Show all Array-Elements
I := 1
FOR I := 1 TO LEN(aData)
Msgalert( aData[1] )
NEXT

// Delete all Elements with .T.
I := 1
Y := LEN( aData )
FOR I := 1 TO Y
IF aData[2] = .T.
ADEL( aData,I )
Y-- // Reduce Array-Length - 1 ( dynamic FOR / NEXT )
AADD(aNEWARRAY, { aData[1], .F.}) // Optional save all .F. to a new Array
ENDIF
NEXT

// Shows 102, 103, 105 ( original ARRAY with only .F.)
I := 1
FOR I := 1 TO Y ( Y = new Array-length )
Msgalert( aData[1] )
NEXT

// Optional
I := 1
FOR I := 1 TO LEN( aNEWARRAY )
Msgalert( aNEWARRAY[1] )
NEXT


Best Regards
Uwe :lol:
Last edited by ukoenig on Tue Jul 27, 2010 10:22 am, edited 3 times in total.
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: ARRAY

Post by nageswaragunupudi »

This is simpler

Code: Select all

AEval( AClone( aData ), { |a,i| If( a[ 2 ], ADel( aData, i, .t. ), ) } )
Regards

G. N. Rao.
Hyderabad, India
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

Re: ARRAY

Post by hua »

Take note, in Rao's code, ADel() has 3 parameter. The 3rd parameter is an xHarbour extension which I think is not supported by Harbour
FWH 11.08/FWH 19.03
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: ARRAY

Post by nageswaragunupudi »

hua wrote:Take note, in Rao's code, ADel() has 3 parameter. The 3rd parameter is an xHarbour extension which I think is not supported by Harbour
This works with Harbour too. Just link xhb.lib. Harbour make file in samples folder includes this lib
Regards

G. N. Rao.
Hyderabad, India
User avatar
mmercado
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Re: ARRAY

Post by mmercado »

Dear Rao:
nageswaragunupudi wrote: This works with Harbour too. Just link xhb.lib. Harbour make file in samples folder includes this lib
The function in xhb.lib that does the job is named xhb_adel()

Best regards.

Manuel Mercado Gómez.
manuelmercado at prodigy dot net dot mx
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: ARRAY

Post by nageswaragunupudi »

Thanks Mr. Mercado.
Yes. You are right.
If we need syntax compatibility with xharbour, we need to include xhb.ch in the program file and link it with xhb.lib.

The logic I posted above is faulty.
Here is the corrected one

Code: Select all

#include "Fivewin.ch"
#ifndef __XHARBOUR__
#include "xhb.ch"
#endif

function main()

   local aData := { { 1, .t. }, { 2, .f. }, { 3, .t. }, { 4, .f. } }
   local n := 1

   xbrowse( aData )
   AEval( AClone( aData ), { |a,i| If( a[ 2 ], ADel( aData, n, .t. ), n++ ) } )
   xbrowse( aData )

return nil
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
MdaSolution
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: ARRAY

Post by MdaSolution »

thanks to all.
I corrected the error .
FWH .. BC582.. xharbour
Post Reply