MSP 2000/2002/2003 VBA API Bug - View and Table switching

From: Robert Emmery (anonymous_at_discussions.microsoft.com)
Date: 04/01/04


Date: Wed, 31 Mar 2004 23:36:09 -0800

Bug #1 - API parameter values are language specific
------
There seems to be a serious limitation in all MSP versions that prohibits
developers from writing language independent code that references views and
tables. The problem is that MSP API requires English strings such as "Gantt
View" and "Entry" to be passed as parameter values when switching between
various views and tables. These stings however cannot be retrieved anywhere
in the system which forces the programmers to localize their code. I would
think that the need to localize code in most cases indicates a serious
flaw in the design of either the language or the API. UI localization is
something quite different. In MSP VBA, if your code references views and
tables the way that MSP API suggests, your code would not run in a French
version of MSP since the French application expects strings "Diagramme de
Gantt" and "Entree" instead of "Gantt Chart" and "Entry".

    ApplyView "Gantt View" ' causes error dialog in French MSP

Bug #2 - Application.EditTable and other methods in this category require
         existing object name to create a new table
-------
One way to avoid bug #1 would be to create your own views and
tables and forget about using the default ones. As it turns out, this
creates the same language dependency problem since view and table creation
APIs require that you pass names of the existing views or tables.

   ' The following line causes error dialog in French MSP
   TableEdit Name:="Entry", TaskTable:=False, Create:=True, _
       NewName:="MyEntryTable"

   ' The following line plainly does not work, in spite of contradicting
   ' API specification
   TableEdit Name:="MyEntryTable", TaskTable:=False, Create:=True

Bug #3 - ViewEdit's Screen parameter doesn't seem to be used at all
--------
A possible workaround for Bug #2 could be to pick the first table name from
the collection of table names (Application.ActiveProject.ResourceTableList)
and the first view name from the collection of view names
(Application.ActiveProject.ResourceViewList). This however will not work for
certain views as the "Screen" parameter in ViewEdit doesn't seem to be used
at all. Instead the value appears to be taken from the view that you are
copying from. To see the problem, try creating your own Resource Usage view
that has the same look and feel as the default "Resource Usage", but instead
of specifying the source view name "Resource Usage" use the first view you
get from the Application.ActiveProject.ResourceViewList. The view you are
creating should have the screen type PjViewScreen.pjResourceUsage which
renders the screen in two halves, left with the table, and right with the
graphical data. Basically, the following code will not do the right thing in
any of the MSP versions:

    'disable dialogs
    MSProject.DisplayAlerts = False
    'copy views from global to active
    Application.OrganizerMoveItem Type:=pjViews, FileName:="Global.mpt", _
         TofileName:=ActiveProject.FullName
    'enable dialogs
    MSProject.DisplayAlerts = True

    templateTableName = Application.ActiveProject.ResourceTableList.Item(1)
    newTableName = "MyTable"
    templateViewName = Application.ActiveProject.ResourceViewList.Item(1)
    newViewName = "MyResUsageView"

    TableEdit Name:=templateTableName, TaskTable:=False, _
       Create:=True, NewName:=newTableName
    ViewEditSingle Name:=templateViewName, NewName:=newViewName, _
       Create:=True, Screen:=PjViewScreen.pjResourceUsage, _
       ShowInMenu:=True, Table:=newTableName
    ViewApply newViewName

The screen type in the VieEditSingle line is taken from templateViewName's object and not the "Screen" parameter.

There is actually a workaround for bug #3 in MSP2002 and MSP2003 thanks to their extended object model which now makes ViewsSingle and Table objects collections accessible to programmers. With these objects available to the programmers, we can now search for a view in the list that has the screen type pjViewScreen.pjResourceUsage. The following code will do what we want, but only in MSP2002 and higher:

Sub setupOracleResourceUsageView()

    MSProject.DisplayAlerts = False
    Application.OrganizerMoveItem Type:=pjViews, FileName:="Global.mpt", _
         TofileName:=ActiveProject.FullName
    MSProject.DisplayAlerts = True

    ' Get any task table name
    templateTableName = ActiveProject.ResourceTableList.Item(1)
    ' Get first resource usage view and use it as a view template
    For Each viewObject In ActiveProject.ViewsSingle
        If viewObject.Screen = pjResourceUsage Then
            templateViewName = viewObject.Name
            GoTo endLoop
        End If
    Next viewObject

endLoop:

    newTableName = "RobsUsageTable"
    newViewName = "RobsUsageView"

    If templateTableName <> Empty And templateViewName <> Empty Then
     ' First delete the table and view
     ' To be implemented...

     ' Create table
     TableEdit Name:=templateTableName, TaskTable:=False, Create:=True, _
               NewName:=newTableName

     ' Create view
     ViewEditSingle Name:=templateViewName, NewName:=newViewName, _
      Create:=True, Screen:=PjViewScreen.pjResourceUsage, _
      ShowInMenu:=True, Table:=newTableName

     ' Switch to new view
     ViewApply newViewName
 Else
   ' Error. Was not able to find template view or table (should no really
   ' happen)
End If

End Sub



Relevant Pages

  • Re: Tired of 100s of stupid Getter/Setter methods
    ... > reading the documentation that the library developer wrote. ... ability to become familiar with an API. ... Given the choice between finding out about a bug as I'm writing the ... say about a language that's one of the more readable that I work in. ...
    (comp.lang.java.programmer)
  • Re: Sockets, writing data and shutdownOutput
    ... > This does not look like merely closing the output ... was just a few nanometers away from stepping on yet another bug in Sun's ... library API into the big bad world. ... and resources in PREVENTING such bugs creeping in in the first place... ...
    (comp.lang.java.programmer)
  • Re: Weird bug in MS Project 2003 Resource Leveling
    ... leveling is also very weak on FF relations. ... > I am a member of PMI Sydney and recently attend meetings at PMI Western ... I haven't met the resident MSP expert or MS rep/distributor yet ... >>> I wish I had discovered a real bug. ...
    (microsoft.public.project)
  • Re: What is QWPZHPT1 ??
    ... now it's V5.3 and the bug is still there. ... I also have had many customer complain about this with HPT printers and using software that uses the HPT API. ... Similar reports work just fine. ... The only thing I could think of is if there was some bad data in the report somewhere, but I never found any (must be that CPYSPLF removed the bad data if there was any). ...
    (comp.sys.ibm.as400.misc)
  • Re: fix iounmap and a pageattr memleak (x86 and x86-64)
    ... I'd never use a 32bit kernel on a x86-64 box, ... interest bug to me, but acked. ... API, I'm not going to care if you want it back, but if there are 3 ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)