Cast Resource Object - missing method CTYPE -

A

alex

Hi,

Context:
Get an object resource from a task => It's ok
Put the object resource in an array => I think ok, but not sure
Convert the object from array as resource

I try to modify the behavior of project for the remaining work
So I decide to modify the planning according with the baseline.


I browse the resource of one task because I should save the work and actual
work.
But I encountered any issue.
When I see with the spy in vba the object R is equal to 1. I click on the
button expand and I can see the details.
So I expected to put the object R in my array and browse R later.
But I see with the spy MyResourcesTab(i) = 1. so I think it's because VBA in
project don't manage really the object.
I try to use CTYPE but is not exist and CVAR doesn't apply here.

So before to use two arrays and add the work in the first and the actual
work in the second, I ask you if you have already
work with object and know how I can solve it.


ReDim MyResourcesTab(T.Resources.Count)

For Each R In T.Resources
MyResourcesTab(i) = R

MyR = CVar(MyResourcesTab(i))
i = i + 1
Next R

######################"CODE##############################""
Sub PlanificationInitiale()
Dim T As Task
Dim R As Resource
Dim i As Integer
i = 0
Dim numberTab As Integer
Dim MyResourcesTab()

For Each T In ActiveProject.Tasks
If Not (T Is Nothing) Then

If (T.Name = "Tache2") Then
ReDim MyResourcesTab(T.Resources.Count)

For Each R In T.Resources
MyResourcesTab(i) = R

MyR = CVar(MyResourcesTab(i))
i = i + 1
Next R
End If

numberTab = i

If (T.Summary <> "Vrai" And T.Name = "Tache2" And T.Type =
pjFixedDuration) Then
If (DateDiff("d", T.BaselineStart, T.Start) < 0) Then
'rétablir la date de début
T.Start = T.BaselineStart
End If

If (DateDiff("d", T.BaselineStart, T.Start) > 0) Then
'rétablir la date de début
T.Start = T.BaselineStart
End If

T.Duration = T.BaselineDuration

If (DateDiff("d", T.BaselineFinish, T.Finish) < 0) Then
T.Finish = T.BaselineFinish
End If

If (DateDiff("d", T.BaselineFinish, T.Finish) > 0) Then
T.Finish = T.BaselineFinish
End If
End If

i = 0
If (T.Name = "Tache2") Then
For Each R In T.Resources
R.Work = MyResourcesTab(i).Work
R.ActualWork = MyResourcesTab(i).ActualWork
i = i + 1
Next R
End If
End If
Next T
End Sub
#############################################################

Thank you,

Best regards,
Alexandre BARAULT
 
J

John

alex said:
Hi,

Context:
Get an object resource from a task => It's ok
Put the object resource in an array => I think ok, but not sure
Convert the object from array as resource

I try to modify the behavior of project for the remaining work
So I decide to modify the planning according with the baseline.


I browse the resource of one task because I should save the work and actual
work.
But I encountered any issue.
When I see with the spy in vba the object R is equal to 1. I click on the
button expand and I can see the details.
So I expected to put the object R in my array and browse R later.
But I see with the spy MyResourcesTab(i) = 1. so I think it's because VBA in
project don't manage really the object.
I try to use CTYPE but is not exist and CVAR doesn't apply here.

So before to use two arrays and add the work in the first and the actual
work in the second, I ask you if you have already
work with object and know how I can solve it.


ReDim MyResourcesTab(T.Resources.Count)

For Each R In T.Resources
MyResourcesTab(i) = R

MyR = CVar(MyResourcesTab(i))
i = i + 1
Next R

######################"CODE##############################""
Sub PlanificationInitiale()
Dim T As Task
Dim R As Resource
Dim i As Integer
i = 0
Dim numberTab As Integer
Dim MyResourcesTab()

For Each T In ActiveProject.Tasks
If Not (T Is Nothing) Then

If (T.Name = "Tache2") Then
ReDim MyResourcesTab(T.Resources.Count)

For Each R In T.Resources
MyResourcesTab(i) = R

MyR = CVar(MyResourcesTab(i))
i = i + 1
Next R
End If

numberTab = i

If (T.Summary <> "Vrai" And T.Name = "Tache2" And T.Type =
pjFixedDuration) Then
If (DateDiff("d", T.BaselineStart, T.Start) < 0) Then
'rétablir la date de début
T.Start = T.BaselineStart
End If

If (DateDiff("d", T.BaselineStart, T.Start) > 0) Then
'rétablir la date de début
T.Start = T.BaselineStart
End If

T.Duration = T.BaselineDuration

If (DateDiff("d", T.BaselineFinish, T.Finish) < 0) Then
T.Finish = T.BaselineFinish
End If

If (DateDiff("d", T.BaselineFinish, T.Finish) > 0) Then
T.Finish = T.BaselineFinish
End If
End If

i = 0
If (T.Name = "Tache2") Then
For Each R In T.Resources
R.Work = MyResourcesTab(i).Work
R.ActualWork = MyResourcesTab(i).ActualWork
i = i + 1
Next R
End If
End If
Next T
End Sub
#############################################################

Thank you,

Best regards,
Alexandre BARAULT

Alexandre,
I didn't study your code in detail but I see one problem right away. You
have a ReDim statement inside a For Each loop. It will build the array
for the first task but then reset that array for subsequent times
through the loop. You might want to consider using a two dimensional
array with one index for the task and the second index for the actual
value.

John
Project MVP
 
A

alex

Hi John,

effectivly you're right.
I did that. I didn't post the solution before I'm sorry you lost your time
to answer.


If (T.Name = "Tache2") Then
ReDim MyResourcesTab(T.Resources.Count, 2)
For Each R In T.Resources
MyResourcesTab(i, 0) = R.Work
MyResourcesTab(i, 1) = R.ActualWork
i = i + 1
Next R
End If

best regards,
Alexandre BARAULT
 
J

John

alex said:
Hi John,

effectivly you're right.
I did that. I didn't post the solution before I'm sorry you lost your time
to answer.


If (T.Name = "Tache2") Then
ReDim MyResourcesTab(T.Resources.Count, 2)
For Each R In T.Resources
MyResourcesTab(i, 0) = R.Work
MyResourcesTab(i, 1) = R.ActualWork
i = i + 1
Next R
End If

best regards,
Alexandre BARAULT

Alexandre,
No problem. Glad you figured it out.

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