looping code and variables help needed

B

Buster

I would like to loop through the following code, each time substituting
pjtask with pjresource, then pjassignment.

How do I loop around this code and insert the variables one at a time.

===============================================
myType = "Finish"
usedfields = usedfields & vbCrLf & "--" & UCase(myType) & "--" & vbCrLf
For i = 1 To 10
mycheck = False
it = 0
While Not mycheck And (it < ts.Count)
it = it + 1
If Not ts(it) Is Nothing Then
If ts(it).GetField(FieldNameToFieldConstant(myType & i,
pjTask)) <> "NA" Then
usedfields = usedfields & myType & CStr(i) & vbCr
mycheck = True
End If
End If
Wend
Next i

MsgBox usedfields
 
J

John

Buster said:
I would like to loop through the following code, each time substituting
pjtask with pjresource, then pjassignment.

How do I loop around this code and insert the variables one at a time.

===============================================
myType = "Finish"
usedfields = usedfields & vbCrLf & "--" & UCase(myType) & "--" & vbCrLf
For i = 1 To 10
mycheck = False
it = 0
While Not mycheck And (it < ts.Count)
it = it + 1
If Not ts(it) Is Nothing Then
If ts(it).GetField(FieldNameToFieldConstant(myType & i,
pjTask)) <> "NA" Then
usedfields = usedfields & myType & CStr(i) & vbCr
mycheck = True
End If
End If
Wend
Next i

MsgBox usedfields

Buster,
Your code snippet is a bit confusing but it looks like you want to check
each of the spare Finish fields for tasks and when the first used field
is detected, note it and move on to the next spare field.

First, the GetField Method only applies to Tasks and Resources. Another
approach will have to be used for Assignments. I suggest a case
statement to cycle through all ten spare assignment finish fields.

Second, there are several ways to loop through all Tasks, Resources and
Assignments. Since the loop is relatively simple, one method is to set
up a separate loop each for Task and Resource object types. The loop for
Assignments can be embedded in either the Task or Resource loop.

Third, the "mycheck" boolean and "it" index variables are not really
necessary. Instead, why not use a "For Each" structure. Then when the
first "active" spare field is detected, simply exit the For loop and
look at the next spare field. For example:
For Each t in ActiveProject.Tasks
If Not t is Nothing then
If t.GetField . . .
usedfields = . . .
Exit For
End If
End If
Next t

Hope this helps.
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top