ARRAY

ARRAY

Postby MdaSolution » 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
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm

Re: ARRAY

Postby ukoenig » Tue Jul 27, 2010 1: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 :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
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: ARRAY

Postby nageswaragunupudi » Tue Jul 27, 2010 7:35 am

This is simpler
Code: Select all  Expand view
AEval( AClone( aData ), { |a,i| If( a[ 2 ], ADel( aData, i, .t. ), ) } )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10628
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: ARRAY

Postby hua » Tue Jul 27, 2010 9: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
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: ARRAY

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10628
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: ARRAY

Postby mmercado » 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
User avatar
mmercado
 
Posts: 782
Joined: Wed Dec 19, 2007 7:50 am
Location: Salamanca, Gto., México

Re: ARRAY

Postby nageswaragunupudi » Wed Jul 28, 2010 1: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: Select all  Expand view
#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
nageswaragunupudi
 
Posts: 10628
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: ARRAY

Postby MdaSolution » Wed Jul 28, 2010 8:21 am

thanks to all.
I corrected the error .
FWH .. BC582.. xharbour
User avatar
MdaSolution
 
Posts: 401
Joined: Tue Jan 05, 2010 2:33 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 83 guests