You can develop powerful Visual Basic applications with the PS/nVision Visual Basic programming interface. The objects and related methods referenced in this section provide the ability to call PS/nVision features programmatically for common reporting and analysis tasks. This chapter describes:
Designer object methods.
Session object methods.
Instance hooks.
Note. Object methods are listed in order based on their functionality.
Creates an instance of PS/nVision.
The following is an example.
Dim objnVision As Object Dim objDesignerCmd As Object Dim strAppName As String strAppName = "PSnvision.nvsdesigner" Set objnVision = CreateObject(strAppName) Set objDesignerCmd = objnVision.DesignerCmd
After you finish with the Designer object, clear the PS/nVision object by setting it equal to nothing, as in the following example:
Set objnVision = Nothing
The following shows details of designer object methods.
Syntax
Connect([in, optional] BSTR startMacro)
Description
This method enables the user to sign on to the PeopleTools application.
Example
‘ Straight Connection objDesignerCmd.Connect ‘ Connection and run macro objDesignerCmd.Connect("MacroName")
Description
This method enables the user to sign off from the PeopleTools application.
Example
objDesignerCmd.Disconnect
Description
This method resets the working directory and other environment settings needed for PS/nVision to process reports.
Example
objDesignerCmd.ResetEnvironment
Description
This method causes the designer to register its menu within the grid.
Example
objDesignerCmd.StartMenu
Description
This method refreshes the designer window, including PS/nVision menus.
Example
objDesignerCmd.OnWindow
Syntax
OpenFile([in] BSTR filename, [in, optional] BOOL updatelinks, [in, optional] BOOL readonly)
Description
This method opens a new or existing PS/nVision report layout.
Parameters
There are three arguments associated with this method: the file name (with full path) and two optional arguments: update links and read only.
Example
ObjDesignerCmd.OpenFile("c:\user\BALANCE.xls", TRUE, FALSE)
Description
This method opens an existing layout.
Example
objDesignerCmd.OpenLayout
Description
This method creates a new layout.
Example
objDesignerCmd.NewLayout
Description
This method saves the worksheet as a layout.
Example
objDesignerCmd.SaveAsLayout
Description
This method invokes the PS/nVision Layout Definition dialog box.
Example
objDesignerCmd.DefineLayout
Description
This method invokes the PS/nVision Layout Options dialog box.
Example
objDesignerCmd.LayoutOptions
Description
This method opens an existing report request.
Example
objDesignerCmd.ReportRequest
Description
This method runs a defined or previously opened report request.
Example
objDesignerCmd.RunCurrent
Syntax
RunReport([in] BSTR BusUnit, [in] BSTR RptRqst)
Description
This runs a specific report.
Parameters
There are two arguments required for this request: business unit and report request name. The report request must be in uppercase letters.
Example
objDesignerCmd.RunReport("M04", "BALANCE")
Description
This to opens the Options dialog box.
Example
objDesignerCmd.Options
Description
Same as LayoutOptions with just one selection.
Example
objDesignerCmd.PerfOpts
Description
This method displays the Open Scope dialog box and then the Scope Definition dialog box, assuming the user chooses a scope.
Example
objDesignerCmd.OpenScope
Description
This method invokes the Scope Definition dialog box.
Example
objDesignerCmd.ScopeDefn
Description
Initiate DrillDown sequence.
Example
objDesignerCmd.DrillDown
Description
Performs a DrillDown using the specified child layout.
Example
objDesignerCmd.DrillLayout
Description
If a default DrillDown layout is defined (as DefaultDrill) in the active instance, drills down using that layout.
For ledger reports, the default drill string may include a D, which indicates that any summary ledgers should be translated to detail. If no default layout is defined, for a query-based instance, drill down to that query in DrillQuery (QueryLink) mode. For a ledger-based instance, have the user select the DrillDown layout, as in DrillDown.
Example
objDesignerCmd.AutoDrill
Description
Drills the selected cell using the most recently selected DrillDown layout.
Example
objDesignerCmd.ReDrill
Description
Performs a DrillDown using the specified query.
Example
objDesignerCmd.DrillQuery
Description
Implements commands to activate the parent instance of the current child DrillDown.
Example
objDesignerCmd.JumpBack
Description
Runs the specified query with no inherited criteria. Not used for DrillDown.
Example
objDesignerCmd.RunQuery
This object retrieves information about the current session.
The following is an example.
Dim objnVision As Object Dim objSessionCmd As Object Dim strAppName As String Dim strDatabaseType As String strAppName = "PSnvision.nvsdesigner" Set objnVision = CreateObject(strAppName) Set SessionCmd = objnVision.SessionCmd
After finishing with the session object, clear the PS/nVision object by setting it equal to nothing, as in the following example:
Set objnVision = Nothing
The following shows details of the session object methods.
Description
This property retrieves database types for the current session.
Example
strDatabaseType = SessionCmd.DBType
Description
This property retrieves the database’s name for the current session.
Example
strDatabaseName = SessionCmd.DBName
Description
This property retrieves the tool release database version for the current session.
Example
strToolReleaseDatabase = SessionCmd.ToolsRelDB
Description
This property retrieves the server’s name for the current session. It retrieves nothing if the user is logged on in two-tier.
Example
strServerName = SessionCmd.ServerName
Description
This property retrieves the user’s ID for the current session.
Example
strOperatorId = SessionCmd.OprId
Description
This property identifies whether or not the current session is two-tier. If the return value is TRUE (or a value of 1), the current session is two-tier.
Example
bTwoTier = SessionCmd.TwoTier
Description
This property retrieves or sets a ShowWarnings option for the current session.
Example
Retrieve Example:
Dim bShowWarnings As Boolean bShowWarnings = SessionCmd.ShowWarnings
Set Example:
Dim bShowWarnings as Boolean bShowWarnings = True SessionCmd.ShowWarnings = bShowWarnings
Description
The AmountSql property retrieves or sets an Amount SQL option for the current session.
Example
Retrieve Example:
Dim bAmountSql As Boolean bAmountSql = SessionCmd.AmountSql
Set Example:
Dim bAmountSql as Boolean bAmountSql = True SessionCmd.AmountSql = bAmountSql
Syntax
ReadConfig([in] BSTR ConfigDir)
Description
This method retrieves the directory paths of a given PS/nVision Configuration Manager setting (as defined in the Windows Registry). If the user has multiple directory paths in the same configuration setting, it retrieves them all. The available configuration settings that can be retrieved are:
InstanceDir
LayoutDir
TemplateDir
MacroDir
StyleDir
DrillDownDir
Example
Dim strDirPath as String strDirPath = SessionCmd.ReadConfig("LayoutDir")
Syntax
ReadConfigDir([in] BSTR ConfigDir, [in] WORD nPosition)
Description
This method retrieves one directory path of a given PS/nVision Configuration Manager setting (as defined in the Windows Registry). This differs from the ReadConfig method: it parses out the list of available directories by providing a number representing the position of the directory in the list. For example, if you had two directories, such as c:\user\nVison\layout and c:\user, and you wanted just the c:\user directory, you would pass in the number two. If the user is looking for the second directory and there is only one, then nothing is retrieved. The list of available configuration settings that can be retrieved is as follows:
InstanceDir
LayoutDir
TemplateDir
MacroDir
StyleDir
DrillDownDir
Example
Dim strDirPath as String strDirPath = SessionCmd.ReadConfig("LayoutDir", 2)
This retrieves the second directory listed.
Beginning with Excel 97, Microsoft began using Visual Basic as the programming language to write macros. In earlier versions of Excel, you had to create a macro sheet to use the NvsInstanceHook. Now, whether recording your macro or writing Visual Basic code within the Visual Basic Editor, you can invoke the PS/nVision Instance Hook directly from the module within a Visual Basic project without having to create a macro sheet.
Instance hooks allow user-written macros to be executed by PS/nVision after delivering the data to a report instance but before saving the instance. Instance hooks are supported for both matrix and tabular layout sheets. With an instance hook, you can:
Refresh a pivot table based on data delivered in the instance.
Change the delivered outline level. (For example, compress reports so the user starts with the top level.)
Apply subtotals or AutoFilter to data delivered in a tabular instance.
Do high-level zero-suppression or resort data.
In general, use Excel features that can't be applied in the layout because they require data.
Within an Instance Hook macro, you can call any other Visual Basic methods or functions. But you should avoid calling PS/nVision functions and closing Excel.
To use instance hooks, identify the layout sheets in the layout workbook (.XNV file) to which you want to apply post-delivery processing. For each sheet, define the name NvsInstanceHook to refer to the name of the first cell of an Excel 4 macro sheet or the name of a Visual Basic procedure.
The defined name NvsInstanceHook is sheet-specific. You need to either define the same name on multiple sheets or, the preferred method, enter the sheet name and an exclamation point (!) with the name when defining it. By doing this you can fire different macros for different layout sheets in the same workbook. The resulting name looks like Sheet1!NvsInstanceHook.
To record a macro from within Excel, select Tools, Macro, Record a Macro.
To write a macro from within Excel, select Tools, Macro, Visual Basic Editor.
The following example shows a module that combines a recorded macro with additional code that has been added through the editor.
The macro bolds and right-aligns the nPloded TimeSpan columns, collapses the outline of the nPloded rows and columns, and saves the instance.
After creating the macro module, return to your PS/nVision layout and attach it using NvsInstanceHook.
To attach a macro using NvsInstance Hook:
Select the cell in the layout.
Select Insert, Name, Define.
For the name, enter the sheet name followed by an exclamation point and the text NvsInstanceHook. For example, Sheet 1!NvsInstanceHook.
Enter the name of the macro in the Refers to field.
For the name, enter the name of Excel Visual Basic Module, where the macro is located, followed by a period and the name of the Excel VB Macro. For example, Module1.MacroName
Click Add.
Click OK.
Your macro is executed after the PS/nVision Instance is created.