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
ARRAY
Re: ARRAY
// 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
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
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.
i work with FW.
If you have any questions about special functions, maybe i can help.
- nageswaragunupudi
- Posts: 10702
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 6 times
- Contact:
Re: ARRAY
This is simpler
Code: Select all | Expand
AEval( AClone( aData ), { |a,i| If( a[ 2 ], ADel( aData, i, .t. ), ) } )
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 10702
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 6 times
- Contact:
Re: ARRAY
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
G. N. Rao.
Hyderabad, India
Re: ARRAY
Dear Rao:
Best regards.
Manuel Mercado Gómez.
The function in xhb.lib that does the job is named xhb_adel()nageswaragunupudi wrote:This works with Harbour too. Just link xhb.lib. Harbour make file in samples folder includes this lib
Best regards.
Manuel Mercado Gómez.
manuelmercado at prodigy dot net dot mx
- nageswaragunupudi
- Posts: 10702
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 6 times
- Contact:
Re: ARRAY
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
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
#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
G. N. Rao.
Hyderabad, India
- MdaSolution
- Posts: 401
- Joined: Tue Jan 05, 2010 2:33 pm