FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour ARRAY
Posts: 401
Joined: Tue Jan 05, 2010 02:33 PM

ARRAY

Posted: Mon Jul 26, 2010 11:55 PM

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
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM

Re: ARRAY

Posted: Tue Jul 27, 2010 01:12 AM
// 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[I][1] )
NEXT

// Delete all Elements with .T.
I := 1
Y := LEN( aData )
FOR I := 1 TO Y
IF aData[I][2] = .T.
ADEL( aData,I )
Y-- // Reduce Array-Length - 1 ( dynamic FOR / NEXT )
AADD(aNEWARRAY, { aData[I][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[I][1] )
NEXT

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


Best Regards
Uwe :-)
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.
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: ARRAY

Posted: Tue Jul 27, 2010 07:35 AM
This is simpler
Code (fw): Select all Collapse
AEval( AClone( aData ), { |a,i| If( a[ 2 ], ADel( aData, i, .t. ), ) } )
Regards



G. N. Rao.

Hyderabad, India
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM

Re: ARRAY

Posted: Tue Jul 27, 2010 09:56 AM

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.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: ARRAY

Posted: Tue Jul 27, 2010 12:03 PM
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
Posts: 782
Joined: Wed Dec 19, 2007 07:50 AM

Re: ARRAY

Posted: Tue Jul 27, 2010 10:11 PM
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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM

Re: ARRAY

Posted: Wed Jul 28, 2010 01:38 AM
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 (fw): Select all Collapse
#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
Posts: 401
Joined: Tue Jan 05, 2010 02:33 PM

Re: ARRAY

Posted: Wed Jul 28, 2010 08:21 AM

thanks to all.
I corrected the error .

FWH .. BC582.. xharbour

Continue the discussion