Microsoft KB Archive/321665

= Len function returns incorrect values when you use it to calculate file properties in Microsoft Project =

Article ID: 321665

Article Last Modified on 1/7/2006

-

APPLIES TO


 * Microsoft Office Project Standard 2003
 * Microsoft Project 2002 Standard Edition

-



This article was previously published under Q321665



SYMPTOMS
In Microsoft Project, when you use the Len function to calculate the number of characters that are contained in the properties of a project file, an incorrect string value is returned.

For example, if the title of your project is defined as MyProject, and you use the Len function to return the string value of the title property, an incorrect value of 10 is returned, instead of the correct value of 9.



CAUSE
This behavior occurs if you use the Len function to return the number of characters contained in the file properties, including the following:

Title

Subject

Author

Manager

Company

Keywords

Comments

The Len function incorrectly returns the string value as length of the property + 1.



RESOLUTION
To work around this issue, use the Len function in a Visual Basic for Applications (VBA) macro. To do this, follow these steps:  Create the macro:  Start Microsoft Project, and then open your project file. Press ALT+F11 to start the Visual Basic Editor. On the Insert menu, click Module.  In the Code window, type the following.

NOTE: In this sample code, the macro returns the string value of the Title property of the file. To return the string value of a different file property, replace &quot;Title&quot; with the name of the property that you want. Sub ProjectTitle

res = Len(ActiveProject.Title)

MsgBox res

End Sub  Press CTRL+S to save the file, and then click Close and Return to Microsoft Project on the File menu.</li></ol> </li> Run the macro: <ol style="list-style-type: lower-alpha;"> Click Tools, point to Macro, and then click Macros.</li> In the Macro name list, select the macro that you created in step 1, and then click Run.

The string value of the file property is displayed.</li></ol> </li></ol>

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

<div class="moreinformation_section">

MORE INFORMATION
Use the Len function in Visual Basic for Applications to calculate the number of characters of a text string that is contained in any object. For more information about the Len, function, type len in a Code window, and then press F1.

Additional query words: prj2002 prj2003

Keywords: kbprogramming kbprb kbnofix KB321665

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.