Agente que eliminos elementos de un campo array

Hola, tengo un campo tipo array en un documento y me gustaria borrar algunos de los elementos de este array, por ejemplo los elementos que fueran "PI". Pasando un agente.
He hecho este agente pero no funciona... :(
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
Alguien sabe como podría hacerlo? Muchas Gracias.

1 Respuesta

Respuesta
1
No le des por valor Null, dale ""
Te paso algunas funciones que te pueden ser útiles
Function ArrayReplaceValue(Array As Variant, OldValue As Variant, NewValue As Variant) As Variant
'This function replace OldValue by New Value of an Array, if Array contains OldValue
Dim i As Integer
If Not (Isarray(NewValue) And Isarray(OldValue)) Then
If Not Isarray(Array) Then
If Array = OldValue Then
Array = NewValue
End If
Else
For i = Lbound(Array) To Ubound(Array)
If Array(i) = OldValue Then Array(i) = NewValue
Next
End If
End If
ArrayReplaceValue = Array
End Function
Function ArrayAddValue(Array As Variant, NewValue As Variant) As Variant
'This function adds NewValue to an Array if NewValue is not contained yet.
Dim Exists As Variant
Dim i As Integer
Dim EmptyPosition As Integer
If Not Isarray(NewValue) Then
If Not Isarray(Array) Then
If Array = "" Then
Array = NewValue
Else
If Array <> NewValue Then
Redim Preserve Array(1)
Array(1) = NewValue
End If
End If
Else
Exists = False
For i = Lbound(Array) To Ubound(Array)
If Array(i) = NewValue Then Exists = True
Next
If Exists = False Then
EmptyPosition = -1
For i = Lbound(Array) To Ubound(Array)
If Cstr(Array(i)) = "" Then EmptyPosition = i
Next
If EmptyPosition > -1 Then
Array(EmptyPosition) = NewValue
Else
Redim Preserve Array(Ubound(Array) + 1)
Array(Ubound(Array)) = NewValue
End If
End If
End If
End If
ArrayAddValue = Array
End Function
Function ArrayContentsComparison(Array1 As Variant, Array2 As Variant) As Variant
'This function comparises the contents (values) of two arrays
'If Array1 contains the same values of Array2, function returns True
'If Array1 not contains the same values of Array2, function returns False
Dim i As Integer, j As Integer
Dim Exists As Variant
'Dimension Comparison
If Isarray(Array1) <> Isarray(Array2) Then
ArrayContentsComparison = False
Exit Function
End If
If (Ubound(Array1) - Lbound(array1)) <> (Ubound(Array2) - Lbound(array2)) Then
ArrayContentsComparison = False
Exit Function
End If
'Contents Comparison
For i = Lbound(Array1) To Ubound(Array1)
Exists = False
For j = Lbound(Array2) To Ubound(Array2)
If Array1(i) = Array2(j) Then Exists = True
Next
If Exists = False Then
ArrayContentsComparison = False
Exit Function
End If
Next
ArrayContentsComparison = True
End Function
Function ArrayComparison(Array1 As Variant, Array2 As Variant) As Variant
'This function comparises two arrays, their dimension, and contents (value and order)
'If Array1 is different to Array2 function returns False
'If Array1 is identicall to Array2 function returns True
Dim i As Integer
Dim Vector1 As Variant
Dim Vector2 As Variant
'Dimension Comparison
If Isarray(Array1) <> Isarray(Array2) Then
ArrayComparison = False
Exit Function
End If
If (Ubound(Array1) - Lbound(array1)) <> (Ubound(Array2) - Lbound(array2)) Then
ArrayComparison = False
Exit Function
End If
'Contents Comparison
If Lbound(Array1) <= Lbound(Array2) Then
Vector1 = Array1
Vector2 = Array2
Else
Vector1 = Array2
Vector2 = Array1
End If
For i = Lbound(Vector1) To Ubound(Vector1)
If Vector1(i) <> Vector2(i + Lbound(Vector2) - Lbound(Vector1)) Then
ArrayComparison = False
Exit Function
End If
Next
ArrayComparison = True
End Function
Function ArrayFusion(Array1 As Variant, Array2 As Variant) As Variant
'This function returns an Array which is made up of all different elents of Array1 and Array2
Dim ArrayGlobal As Variant
Dim i As Integer, j As Integer
Dim inicial As String
If Isarray(Array1) Then
ArrayGlobal = Array1
inicial = "1"
Elseif Isarray(Array2) Then
ArrayGlobal = Array2
inicial = "2"
Else
Redim ArrayGlobal(0)
ArrayGlobal(0) = Array1
inicial = "1"
End If
If inicial ="1" Then
If Isarray(Array2) Then
Else
End If
Else
End If
'Cleanning repeated elements
If Lbound(ArrayGlobal) <> Ubound(ArrayGlobal) Then
For i = Lbound(ArrayGlobal) To Ubound(ArrayGlobal)
For j = Lbound(ArrayGlobal) To Ubound(ArrayGlobal)
If i <> j And ArrayGlobal(i) <> "" And ArrayGlobal(j) <> "" And ArrayGlobal(i) = ArrayGlobal(j) Then
ArrayGlobal(j) = ""
End If
Next
Next
End If
'Cleanning emtpy elements
ArrayGlobal = Fulltrim(ArrayGlobal)
End Function
Tengo funciones que ordenan también

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas