VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "ProcessClass"
Attribute VB_GlobalNameSpace = True
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' ProcessClass (file: DeleteOthers.cls)

' This file implements an Analyst processing script which will delete
' all panes in the frontmost window EXCEPT for the currently active
' pane.

' When the user selects this script from Analyst's "Script" menu, it will
' call the ProcessActive() subroutine.

' A few points to note:
'    (1) The name of the class _MUST_ be "ProcessClass" (although the file
'        name is not important).
'    (2) The class must be part of a Visual Basic "ActiveX DLL" project.
'    (3) The "Instancing" property for this class must be "GlobalMultiUse".
'        If this file is used in other projects (such as "BatchScriptDriver")
'        this property will get automatically reset by VB resulting in an
'        error message when you try to build the DLL ("No creatable public
'        class module detected.").
'    (4) The DLL must be created (using the "Make" item from VB's "File"
'        menu). The resulting DLL is the script which is specified from
'        within Analyst (other files created by VB such as "lib" and "exp"
'        files are not needed).


Option Explicit

' This subroutine is called by Analyst (for post processing scripts only). We
' dispose of all panes in the front window except for the active one.
Public Sub ProcessActive()
    Dim theAnalyst      As Analyst.Application      ' main Analyst object
    Dim numPanes        As Integer                  ' number of panes in front window
    Dim thePanes()      As Object                   ' array of panes in window
    Dim activePane      As Object                   ' currently active pane
    Dim i               As Integer                  ' used to loop over panes
    
    
    ' Get the main Analyst object and the active pane.
    Set theAnalyst = GetObject(, "Analyst.Application")
    Set activePane = theAnalyst.ActiveControl
    
    ' Get the number of panes; if there's at least two, we need to delete some.
    numPanes = theAnalyst.ControlCount
    If numPanes >= 2 Then
        ' Reserve space for the panes.
        ReDim thePanes(1 To numPanes)
        
        ' Get and store all of the panes in the window. We do this because deleting
        ' the panes may change the index required in the GetPane() call; since we
        ' don't know what the effect might be, we get them all and THEN delete them.
        For i = 1 To numPanes
            Set thePanes(i) = theAnalyst.GetPane(i)
        Next i
        
        ' Loop over all the panes asking Analyst to delete them (except for
        ' the active one).
        For i = 1 To numPanes
            If Not (thePanes(i) Is activePane) Then
                Call theAnalyst.DeletePane(thePanes(i))
            End If
        Next i
    End If
End Sub

