FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Adel
Posts: 1956
Joined: Fri Oct 07, 2005 07:08 PM
Adel
Posted: Sat Sep 18, 2021 06: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/
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Adel
Posted: Sat Sep 18, 2021 07:27 PM
Sin FOR NEXT
Code (fw): Select all Collapse
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 (fw): Select all Collapse
aDeleteVarios(a, {|x, n| n >= 5 .and. n <= 8})


Code (fw): Select all Collapse
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
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Adel
Posted: Sun Sep 19, 2021 08:08 PM
For next is the best way
Code (fw): Select all Collapse
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

Continue the discussion