PRJ4: Project 4.0 Constants for Project and Visual Basic

ID: Q124131

The information in this article applies to:

SUMMARY

The following files are available from Microsoft Technical Support.

These files contain global declarations for the Microsoft Project Visual Basic Applications constants.

These constants are available automatically in Microsoft Project. However, if you want to use Microsoft Project OLE Automation objects in a Standard or Professional Edition Visual Basic project, you must either add the PJCONST.BAS or VBACONST.BAS constants files to your Visual Basic project (so that you can use the constants by name), or you must use the numeric values of the constants.

You can open and print these files using any text editor and then use the printouts as references when you write code. The files list the names of all the constants along with their numeric values.

MORE INFORMATION

The following file is available for download from the Microsoft Software Library:

 ~ WP1043.EXE (size: 21263 bytes) 

NOTE: WP1043.EXE contains the files listed in the Summary section.

For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q119591
   TITLE     : How to Obtain Microsoft Support Files from Online Services


WHY USE BUILT-IN CONSTANTS?

When you create Visual Basic procedures in Microsoft Project, you can use constants to represent values that you use frequently. Using constants makes your code easier to read and easier to maintain. For example, if you use the value 8h frequently, you can define a constant called <myvalue>, and then use <myvalue> in your procedure everywhere you would use the value 8h. If you change the value of <myvalue>, you only have to make the change in one location instead of in each place you used the value 8h.

Microsoft Project and Visual Basic, Applications Edition, have built- in constants that are used with functions, methods, objects, and properties. The Microsoft Project built-in constants all begin with the letters "pj," and the Visual Basic, Applications Edition, built-in constants begin with the letters "vb."

When you use built-in constants, your Visual Basic code is easier to read because built-in constants describe the functions they perform. For example, to change the alignment of the text in a column, you could use the following Visual Basic code:

   ColumnAlignment Align:=pjCenter

The built-in constant, pjCenter, is easier to remember than the numeric value it represents. Without using the Microsoft Project built- in constant, the line above would appear as follows:

   ColumnAlignment Align:=1

Note how much more intuitive this line of code is when it contains the built-in constant name.

USING BUILT-IN CONSTANTS WITH VISUAL BASIC PROFESSIONAL OR STANDARD EDITION

To use these constants in the Standard or Professional Editions of Visual Basic, you must declare them. In most cases, you will want to declare them globally by loading them into a code module. If you want to limit the scope of the constants to a form or procedure, change the Global declaration to Const, and paste only the constants you want to use in the Declaration section of the form or procedure.

To load PJCONST.BAS or VBACONST.BAS into a code module:

1. In the Visual Basic Standard or Professional development

   environment, choose the New Module command from the File menu. This
   adds an empty code module to your project.

2. Make sure the module is the active window, and then choose Load
   Text from the File menu.

3. From the List Files Of Type box, select Basic Files (*.BAS).

4. Select one of the global constants files, and choose the Replace

   button. If you want to add the file to a module in which you
   already have other declarations, choose the Merge button.

WHERE ARE BUILT-IN CONSTANTS LISTED IN MICROSOFT PROJECT?

If you want to know which built-in constants are available for a particular function, method, object, or property, search in the Visual Basic Reference in Microsoft Project Help for the item you're looking for or use the Object Browser to view a list of built-in constants.

To use Help to see which built-in constants are available for a particular item:

1. In Microsoft Project, choose Contents from the Help menu.

2. In the Microsoft Project Help Contents window, choose Visual Basic

   Reference.

3. In the Visual Basic Reference window, choose the Search button.

4. In the Search dialog box, type the name of the item (function,

   method, object, or property) you want to view, and choose the Show
   Topics button.

5. From the Topics list, select the item you want to view, and choose
   the Go To button.

All of the built-in constants that are available to the selected item are listed at the bottom of the Help screen. For example, the ColumnAlignment method uses the following three built-in constants: pjLeft, pjCenter, and pjRight. Note that not all items use built-in constants.

To look up constants using the Object Browser:

1. In the Microsoft Project module editor view, choose Object Browser

   from the View menu. (To get to the module editor, choose Macros
   from the Tools menu, and then choose the Edit button.)

2. From the Libraries/Projects list, select MSProject or Visual Basic for
   Applications.

3. From the Classes/Modules list, select Constants.

A list of all of the Microsoft Project built-in constants appears in the Methods/Properties box.

Keywords          : kbappnote kbcode kbprg
Version           : 4.00
Platform          : WINDOWS
Issue type        : kbinfo

Last Reviewed: June 12, 1998