B
BillB
Just so I know it's not me, could someone out there try the following?
Create a new project in MSP 2007 Pro. One work resource assigned to one task
(one unit).
Create a module in the project and paste in the following code:
'-----------------------------------------------
Function tfl(b As Boolean) As Integer
tfl = IIf(b, 1, 0)
End Function
Sub WriteVals()
Dim t As Task, a As Assignment, i
For Each t In ActiveProject.Tasks
Debug.Print t.ID
'For i = 0 To t.Assignments.Count - 1
'Set a = t.Assignments(i + 1) '
For Each a In t.Assignments
With a
Debug.Print .ResourceName
Debug.Print "Names" & vbTab & "1" & vbTab & "2" & vbTab &
"3" & vbTab & "4" & vbTab & "5" & vbTab & "6" & vbTab & "7" & vbTab & "8" &
vbTab & "9" & vbTab & "10" & vbTab & vbTab & "11" & vbTab & "12" & vbTab &
"13" & vbTab & "14" & vbTab & "15" & vbTab & "16" & vbTab & "17" & vbTab &
"18" & vbTab & "19" & vbTab & "20"
Debug.Print "Flags" & vbTab & tfl(.Flag1) & vbTab &
tfl(.Flag2) & vbTab & tfl(.Flag3) & vbTab & tfl(.Flag4) & vbTab &
tfl(.Flag5) & vbTab & tfl(.Flag6) & vbTab & tfl(.Flag7) & vbTab &
tfl(.Flag8) & vbTab & tfl(.Flag9) & vbTab & tfl(.Flag10) & vbTab & vbTab &
tfl(.Flag11) & vbTab & tfl(.Flag12) & vbTab & tfl(.Flag13) & vbTab &
tfl(.Flag14) & vbTab & tfl(.Flag15) & vbTab & tfl(.Flag16) & vbTab &
tfl(.Flag17) & vbTab & tfl(.Flag18) & vbTab & tfl(.Flag19) & vbTab &
tfl(.Flag20)
Debug.Print "Numbers" & vbTab & .Number1 & vbTab & .Number2
& vbTab & .Number3 & vbTab & .Number4 & vbTab & .Number5 & vbTab & .Number6
& vbTab & .Number7 & vbTab & .Number8 & vbTab & .Number9 & vbTab & .Number10
& vbTab & vbTab & .Number11 & vbTab & .Number12 & vbTab & .Number13 & vbTab
& .Number14 & vbTab & .Number15 & vbTab & .Number16 & vbTab & .Number17 &
vbTab & .Number18 & vbTab & .Number19 & vbTab & .Number20
End With
'Next i
Next a
Next t
End Sub
Sub SetVals()
Dim t As Task, a As Assignment
Set t = ActiveProject.Tasks(1)
For Each a In t.Assignments
With a
.Flag1 = True
.Flag2 = True
.Flag3 = True
.Flag4 = True
.Flag5 = True
.Flag6 = True
.Flag7 = True
.Flag8 = True
.Flag9 = True
.Flag10 = True
.Flag11 = True
.Flag12 = True
.Flag13 = True
.Flag14 = True
.Flag15 = True
.Flag16 = True
.Flag17 = True
.Flag18 = True
.Flag19 = True
.Flag20 = True
.Number1 = 1
.Number2 = 1
.Number3 = 1
.Number4 = 1
.Number5 = 1
.Number6 = 1
.Number7 = 1
.Number8 = 1
.Number9 = 1
.Number10 = 1
.Number11 = 1
.Number12 = 1
.Number13 = 1
.Number14 = 1
.Number15 = 1
.Number16 = 1
.Number17 = 1
.Number18 = 1
.Number19 = 1
.Number20 = 1
End With
Next a
End Sub
'------------------------------------------
Run the SetVals sub to set number and flag fields in the assignment.
Save the project in 2003 format and reopen.
Then run the WriteVals sub twice, once with the indexed for loop and once
with the for ... next loop.
I get different values depending on which loop I use. The indexed loop gives
invalid results even with a single resource.
Can anyone else reproduce this? And if it is a problem, can I be sure that
the for each loop will pass through the assignments in the same order every
time?
Thanks,
Bill B
Create a new project in MSP 2007 Pro. One work resource assigned to one task
(one unit).
Create a module in the project and paste in the following code:
'-----------------------------------------------
Function tfl(b As Boolean) As Integer
tfl = IIf(b, 1, 0)
End Function
Sub WriteVals()
Dim t As Task, a As Assignment, i
For Each t In ActiveProject.Tasks
Debug.Print t.ID
'For i = 0 To t.Assignments.Count - 1
'Set a = t.Assignments(i + 1) '
For Each a In t.Assignments
With a
Debug.Print .ResourceName
Debug.Print "Names" & vbTab & "1" & vbTab & "2" & vbTab &
"3" & vbTab & "4" & vbTab & "5" & vbTab & "6" & vbTab & "7" & vbTab & "8" &
vbTab & "9" & vbTab & "10" & vbTab & vbTab & "11" & vbTab & "12" & vbTab &
"13" & vbTab & "14" & vbTab & "15" & vbTab & "16" & vbTab & "17" & vbTab &
"18" & vbTab & "19" & vbTab & "20"
Debug.Print "Flags" & vbTab & tfl(.Flag1) & vbTab &
tfl(.Flag2) & vbTab & tfl(.Flag3) & vbTab & tfl(.Flag4) & vbTab &
tfl(.Flag5) & vbTab & tfl(.Flag6) & vbTab & tfl(.Flag7) & vbTab &
tfl(.Flag8) & vbTab & tfl(.Flag9) & vbTab & tfl(.Flag10) & vbTab & vbTab &
tfl(.Flag11) & vbTab & tfl(.Flag12) & vbTab & tfl(.Flag13) & vbTab &
tfl(.Flag14) & vbTab & tfl(.Flag15) & vbTab & tfl(.Flag16) & vbTab &
tfl(.Flag17) & vbTab & tfl(.Flag18) & vbTab & tfl(.Flag19) & vbTab &
tfl(.Flag20)
Debug.Print "Numbers" & vbTab & .Number1 & vbTab & .Number2
& vbTab & .Number3 & vbTab & .Number4 & vbTab & .Number5 & vbTab & .Number6
& vbTab & .Number7 & vbTab & .Number8 & vbTab & .Number9 & vbTab & .Number10
& vbTab & vbTab & .Number11 & vbTab & .Number12 & vbTab & .Number13 & vbTab
& .Number14 & vbTab & .Number15 & vbTab & .Number16 & vbTab & .Number17 &
vbTab & .Number18 & vbTab & .Number19 & vbTab & .Number20
End With
'Next i
Next a
Next t
End Sub
Sub SetVals()
Dim t As Task, a As Assignment
Set t = ActiveProject.Tasks(1)
For Each a In t.Assignments
With a
.Flag1 = True
.Flag2 = True
.Flag3 = True
.Flag4 = True
.Flag5 = True
.Flag6 = True
.Flag7 = True
.Flag8 = True
.Flag9 = True
.Flag10 = True
.Flag11 = True
.Flag12 = True
.Flag13 = True
.Flag14 = True
.Flag15 = True
.Flag16 = True
.Flag17 = True
.Flag18 = True
.Flag19 = True
.Flag20 = True
.Number1 = 1
.Number2 = 1
.Number3 = 1
.Number4 = 1
.Number5 = 1
.Number6 = 1
.Number7 = 1
.Number8 = 1
.Number9 = 1
.Number10 = 1
.Number11 = 1
.Number12 = 1
.Number13 = 1
.Number14 = 1
.Number15 = 1
.Number16 = 1
.Number17 = 1
.Number18 = 1
.Number19 = 1
.Number20 = 1
End With
Next a
End Sub
'------------------------------------------
Run the SetVals sub to set number and flag fields in the assignment.
Save the project in 2003 format and reopen.
Then run the WriteVals sub twice, once with the indexed for loop and once
with the for ... next loop.
I get different values depending on which loop I use. The indexed loop gives
invalid results even with a single resource.
Can anyone else reproduce this? And if it is a problem, can I be sure that
the for each loop will pass through the assignments in the same order every
time?
Thanks,
Bill B