Examples, IOlapAddIn Interface

The following example shows how to create an add-in program that incorporates Microsoft® SQL Server™ OLAP Services Decision Support Objects (DSO) functionality. A pop-up menu item named List is added to the server tree node with options to list Database, Cube, Dimension, and Level objects. Before you can use this example code, you will need to perform the following steps:

  1. In Microsoft Visual Basic®, create a Microsoft ActiveX® DLL project. Name the project ReportAddIn and the publicly exposed class ReportClass.
  2. Register the add-in program. For more information, see Registering a Custom Add-in Program.
  3. Add a Form to the projects named ReportForm with a ListBox control named ObjectList.

For more information, see Creating a Visual Basic Project.

Option Explicit

Implements IOlapAddIn

Private dsoServer As DSO.Server    'DSO Server object

Private frmReport As ReportForm

Const OLAPManagerName = "OLAP Manager"

Const ThisAddInName = "ReportAddIn"

Private Enum MenuItems

  mnuParentMenuItem = 1

  mnuListDatabase

  mnuListCube

  mnuListDimension

  mnuListLevel

  mnuObjList

End Enum

Private Sub Class_Initialize()

  Set frmReport = New ReportForm

End Sub

Private Function IOlapAddIn_ExecuteMenuItem( _

    CurrentNode As DSSAddInsManager.OlapTreeNode, _

    MenuItem As DSSAddInsManager.OlapMenuItem) _

    As DSSAddInsManager.RefreshTreeTypes

  Dim dsoDB As DSO.MDStore     'Server's Database collection

  Dim dsoCube As MDStore       'Database's Cube collection

  Dim dsoDim As DSO.Dimension  'Cube's Dimension collection

  Dim dsoLev As DSO.Level      'Dimension's Level collection

  Dim DBCounter As Integer

  Dim CubeCounter As Integer

  Dim DimCounter As Integer

  Dim LevCounter As Integer

  

  Select Case MenuItem.Key

    Case mnuListDatabase    'List Database Objects

      frmReport.Caption = "Database Objects"

      For DBCounter = 1 To dsoServer.MDStores.Count

        Set dsoDB = dsoServer.MDStores(DBCounter)

        frmReport.ObjectList.AddItem dsoDB.Name

      Next DBCounter

      

    Case mnuListCube        'List Cube Objects

      frmReport.Caption = "Cube Objects"

      For DBCounter = 1 To dsoServer.MDStores.Count

        Set dsoDB = dsoServer.MDStores(DBCounter)

        frmReport.ObjectList.AddItem dsoDB.Name

        For CubeCounter = 1 To dsoDB.MDStores.Count

          Set dsoCube = dsoDB.MDStores(CubeCounter)

          frmReport.ObjectList.AddItem "  " & dsoCube.Name

        Next CubeCounter

      Next DBCounter

      

    Case mnuListDimension    'List Dimension Objects

      frmReport.Caption = "Dimension Objects"

      For DBCounter = 1 To dsoServer.MDStores.Count

        Set dsoDB = dsoServer.MDStores(DBCounter)

        frmReport.ObjectList.AddItem dsoDB.Name

        For CubeCounter = 1 To dsoDB.MDStores.Count

          Set dsoCube = dsoDB.MDStores(CubeCounter)

          frmReport.ObjectList.AddItem "  " & dsoCube.Name

          For DimCounter = 1 To dsoCube.Dimensions.Count

            Set dsoDim = dsoCube.Dimensions(DimCounter)

            frmReport.ObjectList.AddItem "      " & _

                dsoDim.Name

          Next DimCounter

        Next CubeCounter

      Next DBCounter

      

    Case mnuListLevel        'List Level Objects

      frmReport.Caption = "Level Objects"

      For DBCounter = 1 To dsoServer.MDStores.Count

        Set dsoDB = dsoServer.MDStores(DBCounter)

        frmReport.ObjectList.AddItem dsoDB.Name

        For CubeCounter = 1 To dsoDB.MDStores.Count

          Set dsoCube = dsoDB.MDStores(CubeCounter)

          frmReport.ObjectList.AddItem "  " & dsoCube.Name

          For DimCounter = 1 To dsoCube.Dimensions.Count

            Set dsoDim = dsoCube.Dimensions(DimCounter)

            frmReport.ObjectList.AddItem "      " & _

                dsoDim.Name

            For LevCounter = 1 To dsoDim.Levels.Count

              Set dsoLev = dsoDim.Levels(LevCounter)

              frmReport.ObjectList.AddItem _

                  "          " & dsoLev.Name

            Next LevCounter

          Next DimCounter

        Next CubeCounter

      Next DBCounter

      

  End Select

  

  'Display the form

  frmReport.Show

End Function

Private Function IOlapAddIn_GetObject( _

    LinkedNode As DSSAddInsManager.OlapTreeNode) As Object

End Function

Private Property Get IOlapAddIn_Name() As String

  IOlapAddIn_Name = ThisAddInName

End Property

Private Sub IOlapAddIn_ProvideChildNodes( _

    ParentNode As DSSAddInsManager.OlapTreeNode, _

    OlapTreeNodes As DSSAddInsManager.OlapTreeNodes)

  'No child nodes needed

End Sub

Private Sub IOlapAddIn_ProvideHTML( _

    CurrentNode As DSSAddInsManager.OlapTreeNode, _

    CurrentURL As String)

  'If custom HTML pages are needed -

  'CurrentURL = "{custom.htm}"

End Sub

Private Function IOlapAddIn_ProvideIcon(Index As Integer) _

    As stdole.OLE_HANDLE

  'No Icons needed

End Function

Private Sub IOlapAddIn_ProvideMenuItems( _

    CurrentNode As DSSAddInsManager.OlapTreeNode, _

    MenuItems As DSSAddInsManager.OlapMenuItems)

  Dim iFlags As OlapMenuFlags

  

  If CurrentNode.OwnerAddInName = OLAPManagerName Then

    'Do we have as server?

    If CurrentNode.LinkedObject.ClassType = clsServer Then

      Set dsoServer = CurrentNode.LinkedObject

      

      'If not connected to server, disable menu item

      If dsoServer.State = stateConnected Then

        iFlags = mnuflagRegular + mnuflagPopup

      Else

        iFlags = mnuflagGrayed + mnuflagPopup

      End If

      

      'Add Popup Menu Item

      MenuItems.Add mnuSeparator

      MenuItems.Add mnuStandard, "&List", _

          mnuParentMenuItem, , iFlags

      

      'Add Popup Menu Child Menu Items

      MenuItems.Add mnuStandard, "&Database", _

          mnuListDatabase, mnuParentMenuItem, mnuflagSubmenu

      MenuItems.Add mnuStandard, "&Cube", _

          mnuListCube, mnuParentMenuItem, mnuflagSubmenu

      MenuItems.Add mnuStandard, "&Dimension", _

          mnuListDimension, mnuParentMenuItem, mnuflagSubmenu

      MenuItems.Add mnuStandard, "&Level", _

          mnuListLevel, mnuParentMenuItem, mnuflagSubmenu

    End If

  End If

End Sub

(c) 1988-1998 Microsoft Corporation. All Rights Reserved.