Página 1 de 1

Alguém sabe como excluir elementos de um array?

Enviado: 11 Abr 2008 10:20
por labaroazul
Bom dia, amigos! :))

Alguém sabe como faço para excluir elementos de um array permanentemente?

Estou tentando fazer assim:

Do while Len(aArray) > 0
ADEL(aArray,1)
EndDo

e já tentei fazer assim:

nCampos = Len(aArray)
For V = 1 to nCampos
ADEL(aArray, V)
Next

Só que ambos os métodos não excluem os elementos do Array. Se excluiem, deixam um espaço em branco porque, por exemplo, o Do While fica sendo executado eternamente e, quando eu uso o comando Len(aArray) após o For Next ele me dá o mesmo número de elementos que tinha antes. Deveria ter menos ou nenhum elemento (que é o que eu quero fazer!)

Enviado: 11 Abr 2008 11:28
por MARCELOG
Use assim:

ADEL(aArray, V,.T.)

MarceloG

Enviado: 11 Abr 2008 13:26
por gvc
[labaroazul]
Se é só para limpar:

aarray := {}

O ADEL apaga o valor da posição solicitada, move os elementos posteriores e coloca um Nil na última posição.
Vc deve dar um ASIZE para acertar o tamanho.

[MARCELOG]
Não conheço o terceiro parâmetro do ADEL. Não aparece na documentação que eu tenho. Para quê é?

Enviado: 11 Abr 2008 14:15
por MARCELOG
Ops, é xHarbour:

ADel()
Deletes an element from an array.
Syntax
ADel( <aArray>, <nElement>, [<lShrink>] ) --> aArray

Arguments
<aArray>
A variable holding the array to delete an element from.
<nElement>
This is a numeric expression indicating the ordinal position of the array element to delete. It must be in the range between 1 and Len(<aArray>).
<lShrink>
Optionally, a logical value can be specified. If .T. (true) is passed, the length of the array is reduced by one element. The default value is .F. (false) leaving the number of elements in <aArray> unchanged. Return
The return value is a reference to <aArray>.
Description
The array function ADel() deletes the element at position <nElement> from the array <aArray>. All subsequent elements are shifted up by one position so that the last element contains the value NIL when the function returns. This default behaviour leaves the number of elements in the array unchanged.
If the third parameter <lShrink> is specified as .T. (true), the last element is removed from the array and the number of elements is reduced by 1.

Mas Asize() resolve ('inda' bem né?).

MarceloG

Enviado: 11 Abr 2008 14:15
por Maligno
Mas ADel() tem um terceiro parâmetro? Não seria apenas um erro de digitação?

Enviado: 11 Abr 2008 14:16
por Maligno
Pow! Postamos ao mesmo tempo. Tá explicado então. :)