L
Laurence K
I find that looping through a tasks collection in a project which
contains sub-projects, I get different results depending on the method
used;
- if I use a For/Next loop as in "For each tsk in activeproject.tasks"
I get all tasks including all those in any sub-projects. I can
identify the sub-project tasks by for instance "if tsk.project <>
activeproject.projectsummarytask.project"
- if I use a manual loop through the same collection as in "for i =1
to activeproject.tasks.count" I get only the tasks in the main
project. These include the single summary task representing the
sub-project (which has a Task ID within the main project), but not the
subtasks of the sub-project.
I am probably being stupid, but I would expect these methods to return
the same results - syntactically they seem to be addressing the same
collection. I know from prior performance tuning that a For/Next loop
is massively faster than the "For i = 1 to activeproject.tasks.count"
approach which seems to indicate something very different is going on
under the hood, but I don't understand why I get different task
results.
This isn't a theoretical question as I have a lot of code which needs
to handle sub-projects - the difficulty is that some parts use the
For/Next approach (basically when checking all tasks) whereas other
code has to use the "For i = tskNNN.ID to activeproject.tasks.count"
approach. I have found some workarounds in code, but would like to
understand the basic reasons for the difference.
Probably a TJHIW problem.
Cheers,
L.
contains sub-projects, I get different results depending on the method
used;
- if I use a For/Next loop as in "For each tsk in activeproject.tasks"
I get all tasks including all those in any sub-projects. I can
identify the sub-project tasks by for instance "if tsk.project <>
activeproject.projectsummarytask.project"
- if I use a manual loop through the same collection as in "for i =1
to activeproject.tasks.count" I get only the tasks in the main
project. These include the single summary task representing the
sub-project (which has a Task ID within the main project), but not the
subtasks of the sub-project.
I am probably being stupid, but I would expect these methods to return
the same results - syntactically they seem to be addressing the same
collection. I know from prior performance tuning that a For/Next loop
is massively faster than the "For i = 1 to activeproject.tasks.count"
approach which seems to indicate something very different is going on
under the hood, but I don't understand why I get different task
results.
This isn't a theoretical question as I have a lot of code which needs
to handle sub-projects - the difficulty is that some parts use the
For/Next approach (basically when checking all tasks) whereas other
code has to use the "For i = tskNNN.ID to activeproject.tasks.count"
approach. I have found some workarounds in code, but would like to
understand the basic reasons for the difference.
Probably a TJHIW problem.
Cheers,
L.