Adel

Adel

Postby goosfancito » Sat Sep 18, 2021 6:51 pm

Hola.

Tengo un array y necesito eliminar de la posicion 5 a la 8 (por ejemplo) todos los item.
hay alguna manera de no hacerlo mediante un for... next convinado con un adel?

gracias.
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
goosfancito
 
Posts: 1954
Joined: Fri Oct 07, 2005 7:08 pm

Re: Adel

Postby hmpaquito » Sat Sep 18, 2021 7:27 pm

Sin FOR NEXT
Code: Select all  Expand view
adel(a, 5)
adel(a, 6)
adel(a, 7)
adel(a, 8)
aSize(a, Len(a)- 4)


o bien mi preferida sin FOR NEXT:
Code: Select all  Expand view
aDeleteVarios(a, {|x, n| n >= 5 .and. n <= 8})


Code: Select all  Expand view
FUNCTION aDeleteVarios(a, bCondicionBorrado)
Local nI
Local nBorrados
Local nFinal
Local nItem  // Nº item real
*
nFinal:= Len(a)
nBorrados:= 0
nI:= 1
nItem:= 1
DO WHILE nI <= nFinal
   IF Eval(bCondicionBorrado, a[nI], nItem)
      aDel(a, nI)
      nBorrados++
      nFinal--
   ELSE
      nI++
   ENDIF
   nItem++
ENDDO
aSize(a, Len(a)- nBorrados)
RETURN a
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm


Re: Adel

Postby nageswaragunupudi » Sun Sep 19, 2021 8:08 pm

For next is the best way
Code: Select all  Expand view

for n := 8 to 5 step -1
   ADel( aArray, n, .t. )
next

// OR

for n := 5 to 8
   ADel( aArray, 5, .t. )  // use 5 not 'n'
next
 
Regards

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


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 90 guests