Hello, I have an array field in documents. I want erase some of the elements of the array using an agent. For example I want to delete all the lists elements that have the name “Pi”.
I’m using this, but doesn’t work… 
Set doc = view.GetFirstDocument
While Not ( doc Is Nothing )
n=0
Forall aux In doc.usuarios
If aux="Pi" Then
---->doc.usuarios(n)=Null
End If
n=n+1
End Forall
Set doc = view.GetNextDocument(doc)
Wend
Call doc.save(False,False)
End Sub
Somebody can help me? Thank You SO much.
Subject: Erase a list element
Use ArrayReplace along with the FullTrim function. Check designer help for examples.
Subject: Erase a list element
Hi,
you can do that like this:
…
Dim arrValue() As String
Set doc = view.GetFirstDocument
While Not ( doc Is Nothing )
n=0
Forall aux In doc.usuarios
Redim Preserve arrValue(n)
If aux <> “Pi” Then
arrValue(n) = doc.usuarios(n)
End If
n=n+1
End Forall
doc.usuarios = arrValue
Call doc.save(False,False)
Set doc = view.GetNextDocument(doc)
Wend
…
Regards
Axel
Subject: RE: Erase a list element
Thank you Axel,
Now, you are my Lord.
thank you… thank you… Gracias.
Subject: redim preserve is very expensive; take it out of the loop and the code will run much faster
Dim arrValue() As String
Set doc = view.GetFirstDocument
do until doc Is Nothing
n=0
'first dim the array as big as it could possibly need to be
Redim arrValue(ubound(doc.usarios))
Forall aux In doc.usuarios
Redim Preserve arrValue(n)
If aux <> “Pi” Then
arrValue(n) = doc.usuarios(n)
End If
n=n+1
End Forall
doc.usuarios = arrValue
Call doc.save(False,False)
Set doc = view.GetNextDocument(doc)
loop
'now redim it only as big as it actually needs to be
if n > 0 then Redim Preserve arrValue(n - 1)
Of course, JoyDeep’s suggestion is still a better way of doing it…