Need help substituting variables in loop

B

Buster

I am trying to substitute a palceholde "holder" with variables "pjTask",
pjResources, "pjResourceEnterprise" everytime the loop iterates through the
loop.

when I use the Locals window my variables seem to be right even tjhough I
get an error during the first loop at the "If
ts(it).GetField(FieldNameToFieldConstant(myType & i, holder)) <> "" Then"
line of code.

================================================
Sub Test()
Dim mycheck As Boolean
Dim myType, usedfields As String
Dim T As task
Dim ts As Tasks
Dim i, it As Integer
Dim holder As String
Dim Testing As Integer


Set ts = ActiveProject.Tasks
usedfields = "Custom Fields used in this file" & vbCrLf

For Testing = 1 To 3
If Testing = 1 Then holder = pjTask
If Testing = 2 Then holder = pjResource
If Testing = 3 Then holder = pjResourceEnterprise


myType = "Text"
usedfields = usedfields & vbCrLf & "--" & UCase(myType) & "--" &
vbCrLf
For i = 1 To 30
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,
holder)) <> "" Then
usedfields = usedfields & myType & CStr(i) & vbCr
mycheck = True
End If
End If
Wend
Next i

myType = "Number"
usedfields = usedfields & vbCrLf & "--" & UCase(myType) & "--" &
vbCrLf
For i = 1 To 20
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,
holder)) <> 0 Then
usedfields = usedfields & myType & CStr(i) & vbCr
mycheck = True
End If
End If
Wend
Next i
Next Testing


MsgBox usedfields
End Sub
 
J

JackD

Dim holder as a long.
0 is tasks
1 is resources
2 is assignments

You need a different subroutine for each type of custom field. Iterating
through the tasks and determining which task uses a specific resource custom
field makes no sense.

Finally, if you are going to post my code (and what you have posted below IS
my code), please leave my copyright in it.

Thanks
 
J

Jeff

I tried your suggestion using Holder as long and substituting the
values from the list you provided. I get an error"Argument value not
valid" once Holder gets to the value of "2".

Also, where would I have found the list of values for 0,1,2 that you
supplied. I have searched high and low and cannot find reference to
those numbers.

Thanks
Jeff
\
 
J

JackD

Set a break in your code and look at the value of holder when you set it =
to pjTask.

Sub ReturnConstant()
MsgBox "pjTask " & pjtask
MsgBox "pjResource " & pjResource
End Sub

I was wrong. There is only pjTask and pjResource. So that is why you get an
error with 2.
You will have to change the code to look at "EnterpriseText" if you want
enterprise stuff.
 
B

Buster

JackD said:
Set a break in your code and look at the value of holder when you set it =
to pjTask.

Sub ReturnConstant()
MsgBox "pjTask " & pjtask
MsgBox "pjResource " & pjResource
End Sub

I was wrong. There is only pjTask and pjResource. So that is why you get an
error with 2.
You will have to change the code to look at "EnterpriseText" if you want
enterprise stuff.

--
-Jack ... For project information and macro examples visit
http://masamiki.com/project

.
"--" ts(it).GetField(FieldNameToFieldConstant(myType "--" ts(it).GetField(FieldNameToFieldConstant(myType
 
B

Buster

Thanks Jack. I altered the MyType variables to get the enterprise fields and
it all worked.
 

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