PRJ4: Converting Duration Values |
Q132092
The DurationValue method in Microsoft Project is used to convert a duration
value into the equivalent number of minutes. This conversion is always
based on the current conversion defaults for the application, rather than
the conversion defaults for a specific project.
A custom function can be used in place of DurationValue to return values
based on project-specific conversion defaults.
The DurationValue method takes a duration value as a string argument and
returns an integer number of minutes. If the duration value is specified in
units of Days or Weeks, this conversion is based on the current application
default values for Hours Per Day and Hours Per Week. For example, with the
initial default value for Hours Per Day set to 8.00 using this value, 5d =
40h = 2400m; Application.DurationValue("5d") = 2400.
Changing the Hours Per Day setting for a specific project does not affect
this calculation. For example, making the following change will not affect
this calculation:
Function ProjDurationValue(oProj As Object, sDur As String) As Long
' This function returns the number of minutes equivalent
' to the passed duration based on conversion values in the
' passed project.
' ProjDurationValue returns -1 if an invalid duration value is passed.
' oProj = project whose conversion values we're using
' sDur = duration to convert
ProjDurationValue = -1 ' Return -1 if invalid duration
If InStr(sDur, "e") > 0 Then ' Elapsed duration
Select Case Right(sDur, 2)
Case "ed" ' Elapsed days
'1440 = number of minutes in 1 elapsed day
ProjDurationValue = Val(sDur) * 1440
Exit Function
Case "ew" ' Elapsed weeks
'10080 = number of minutes in 1 elapsed week
ProjDurationValue = Val(sDur) * 10080
Exit Function
End Select
End If
Select Case Right(sDur, 1)
Case "m" ' Minutes and Elapsed Minutes
ProjDurationValue = Val(sDur)
Case "h" ' Hours and Elapsed Hours
ProjDurationValue = Val(sDur) * 60
Case "d" ' Days
Temp = oProj.Duration1
oProj.Duration1 = "1d"
ProjDurationValue = Val(sDur) * 60 * (oProj.Duration1 / 60)
oProj.Duration1 = Temp
Case "w" ' Weeks
Temp = oProj.Duration1
oProj.Duration1 = "1w"
ProjDurationValue = Val(sDur) * 60 * (oProj.Duration1 / 60)
oProj.Duration1 = Temp
End Select
End Function
Additional query words:
Keywords : kbcode kbprogramming
Issue type : kbhowto
Technology : kbHWMAC kbOSMAC kbProjectSearch kbProject400Mac kbProject98Search kbProjectMacSearch kbProject98 kbProject410 kbProject410a kbProject400 kbProject95Search
|
Last Reviewed: November 5, 2000 © 2001 Microsoft Corporation. All rights reserved. Terms of Use. |