PDA

View Full Version : code for near critical activities !!



armchairandy
09-08-2011, 02:23 AM
Guys

What I want is to use a flag field with a code to set Yes to activities with total float bigger than one but less than 4. I have tried the IF then statement but cannot seem to get the range bit. I can do one or the other but not the between bit. Any help would be really appreciated.

Andrew

magdi
09-21-2011, 11:52 PM
I have tried to write a code for the same using "ActiveProject.Tasks.Item(Current_Record).StartSlack" to read the "Start Slak Field" value.
It seems that ".StartSlak" return the "Start Slak Filed" multiplied by some value. So, ".StartSlak" does not match "Start Slak Field".

I used my code with some templates and all .StarSlak were multiplied by 480 !! Which is the "ActiveProject.Tasks.Item(Current_Record).Duration"

So, to read the correct "Start Slak Field" you should use " ActiveProject.Tasks.Item(Current_Record).StartSlack / ActiveProject.Tasks.Item(Current_Record).Duration " to read the correct value

magdi
09-22-2011, 02:00 AM
My Code using Hoursperweek * Hoursperday

Option Explicit
' Constants
Const Lower_Range_Start_Slak = 1
Const Higher_Range_Start_Slak = 4
Sub Create_Near_Critical()
Dim Current_Record As Integer
' Loop for all record to check the Start Slak if it within the defined range
On Error Resume Next

While Current_Record < ActiveProject.Tasks.Count

Current_Record = Current_Record + 1

ActiveProject.Tasks.Item(Current_Record).Flag1 = False

If (ActiveProject.Tasks.Item(Current_Record).StartSlack <= Higher_Range_Start_Slak * ActiveProject.HoursPerDay * ActiveProject.HoursPerWeek) And _
(ActiveProject.Tasks.Item(Current_Record).StartSlack >= Lower_Range_Start_Slak * ActiveProject.HoursPerDay * ActiveProject.HoursPerWeek) Then

ActiveProject.Tasks.Item(Current_Record).Flag1 = True
End If

Wend
End Sub

draco664
09-22-2011, 04:38 PM
Guys

What I want is to use a flag field with a code to set Yes to activities with total float bigger than one but less than 4. I have tried the IF then statement but cannot seem to get the range bit. I can do one or the other but not the between bit. Any help would be really appreciated.

Andrew

You don't need VB to do this. Open 'Customize Fields', select the flag field you want and click Formula.
Enter
IIf([Total Slack]>ProjDurConv("1 day",pjDays) And [Total Slack]<ProjDurConv("4 days",pjDays),Yes,No)
Project stores duration fields in minutes, and since the number of working minutes in a day can be different in individual projects, it's best to use conversion functions where possible.

GROOKNET
03-31-2012, 07:35 AM
Thank you