Nicole said:
Hello John,
I write a message with some code to explain where the problem is.
First I apply a filter and save the tasks’ID in a list. Then I make a list
with the predecessors of all this tasks. I delete all the tasks out of this
list and save this in a new project. We have so many loops.
Here is the code where the error appears:
'Boucle, qui parcourt toutes les tâches du planning actif
'En commençant par la fin du planning
For j = NbTasks To 1 Step -1
'On ne traite que les tâches non récapitulatives,
'car la suppression d'une tâche récapitulative entraine la suppression des
tâches subalternes
If ActiveProject.Tasks(j).Summary = False Then
'Initialisation du booléen OKPlan à faux
OKPlan = False
'Boucle, qui parcourt la liste des prédécesseurs mémorisés dans la matrice
ListPred, pour voir si la tâche y est inscrite
For k = 1 To Compteur
'Si l'ID de cette tâche j est dans la liste des prédécesseurs ListPred, le
booléen est mis à vrai
If (ActiveProject.Tasks(j).ID = ListPred(k)) Then
OKPlan = True
Exit For
End If
Next k
The mistake is on the line: “If (ActiveProject.Tasks(j).ID = ListPred(k))
Thenâ€
Thank you for your help.
Nicole,
I know absolutely no French, so unfortunately I can't follow what you
are saying in your comment lines. Perhaps fellow MVPs, Jan DeMessmaeker
or Gerard Ducouret will jump in and help out if I can't.
I don't fully understand what you are trying to do. It almost sounds
like you are trying to create a new project file from an existing file
by first removing all predecessors. If that is the case there are much
easier ways to do that then to set up arrays for tasks and predecessors.
Nonetheless, in your opening description you mention that you delete
tasks out of the list. If that means that somewhere in your code, you
physically delete tasks from the file, then the ID sequence will change.
If you then try to compare task IDs to your ListPred array, the items
won't match up.
The most common reason why a statement that compares two arrays will
fail is that one or the other array index is out of range. In other
words, the code it trying to access an element of the array that doesn't
exist.
John
Project MVP