PRJ4: Converting Duration ValuesLast reviewed: November 24, 1997Article ID: Q132092 |
The information in this article applies to:
SUMMARYThe 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.
MORE INFORMATIONThe 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:
To change the default value for the entire application
It is also possible to create an equivalent function that returns the number of minutes based on the conversion settings in a particular project. The following example ProjDurationValue function takes a project object and a duration string as arguments, and returns the corresponding number of minutes for that duration. Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.
Sample MacroFunction 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 SelectEnd Function
|
Additional query words: 4.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |