PRJ AppNote: Constants for Project and Visual Basic (WP1043)

Last reviewed: November 24, 1997
Article ID: Q124131
The information in this article applies to:
  • Microsoft Project for Windows, version 4.0

The "Using Visual Basic and Microsoft Project Constants with Visual Basic Standard or Professional Edition" Application Note is now available from Microsoft Product Support Services. This Application Note includes the files that contain global declarations for the Microsoft Project and Visual Basic, Applications Edition, constants. You can obtain this Application Note from the following sources:

  • Microsoft's World Wide Web Site on the Internet
  • The Internet (Microsoft anonymous ftp server)
  • The Microsoft Network (MSN)
  • Microsoft Download Service (MSDL)
  • Microsoft Product Support Services

For complete information, see the "To Obtain This Application Note" section at the end of this article.

THE TEXT OF WP1043

  Microsoft(R) Product Support Services Application Note (Text File)
  WP1043: USING VISUAL BASIC(R) AND MICROSOFT PROJECT CONSTANTS WITH
             VISUAL BASIC STANDARD OR PROFESSIONAL EDITION
                                                  Revision Date: 12/94
                                                                1 Disk

The following information applies to Microsoft Project for Windows(TM), version 4.0.

 ---------------------------------------------------------------------
| INFORMATION PROVIDED IN THIS DOCUMENT AND ANY SOFTWARE THAT MAY     |
| ACCOMPANY THIS DOCUMENT (collectively referred to as an Application |
| Note) IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER      |
| EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED      |
| WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR       |
| PURPOSE. The user assumes the entire risk as to the accuracy and    |
| the use of this Application Note. This Application Note may be      |
| copied and distributed subject to the following conditions: 1) All  |
| text must be copied without modification and all pages must be      |
| included; 2) If software is included, all files on the disk(s) must |
| be copied without modification (the MS-DOS(R) utility diskcopy is   |
| appropriate for this purpose); 3) All components of this            |
| Application Note must be distributed together; and 4) This          |
| Application Note may not be distributed for profit.                 |
|                                                                     |
| Copyright (C) 1994 Microsoft Corporation. All Rights Reserved.      |
| Microsoft, MS-DOS, and Visual Basic are registered trademarks and   |
| Windows is a trademark of Microsoft Corporation.                    |
 ---------------------------------------------------------------------

OVERVIEW

This Application Note includes the following files, which contain global declarations for the Microsoft Project and Visual Basic, Applications Edition, constants:

  • PJCONST.BAS--Microsoft Project global constants file
  • VBACONST.BAS--Microsoft Visual Basic, Applications Edition, global constants file

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.

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.

TO OBTAIN THIS APPLICATION NOTE

You can find WP1043.EXE (size: 21263 bytes) 
                       , a self-extracting file, on the following
services:
  • Microsoft's World Wide Web Site on the Internet

          On the www.microsoft.com home page, click the Support icon.
          Click Knowledge Base, and select the product.
    
          Enter kbfile WP1043.EXE (size: 21263 bytes) 
                                 , and click GO!
          Open the article, and click the button to download the file.
    
    
  • Internet (anonymous FTP)

          ftp ftp.microsoft.com
          Change to the Softlib/Mslfiles folder.
          Get WP1043.EXE (size: 21263 bytes) 
    
  • The Microsoft Network

          On the Edit menu, click Go To, and then click Other Location.
          Type "mssupport" (without the quotation marks).
          Double-click the MS Software Library icon.
          Find the appropriate product area.
          Locate and Download WP1043.EXE.
    
  • Microsoft Download Service (MSDL)

          Dial (425) 936-6735 to connect to MSDL
          Download WP1043.EXE (size: 21263 bytes) 
    

For additional information about downloading, please see the following article in the Microsoft Knowledge Base:

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

  • If you are unable to access the source(s) listed above, you can have this Application Note mailed to you by calling Microsoft Product Support Services Monday through Friday, 6:00 A.M. to 6:00 P.M. Pacific time at (425) 635-7070. If you are outside the United States, contact the Microsoft subsidiary for your area. To locate your subsidiary, see the Microsoft World Wide Offices Web site at:

          http://www.microsoft.com/worldwide/default.htm
    
    Keywords          : kbappnote kbcode kbprg
    Version           : 4.00
    Platform          : WINDOWS
    Issue type        : kbinfo

  • ================================================================================


    THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

    Last reviewed: November 24, 1997
    © 1998 Microsoft Corporation. All rights reserved. Terms of Use.