ÿþPublic colBrowser '========================================= ' Name: Class clsBrowser ' ' Purpose: ' ' Functions: ' Name ' ' Properties: ' colObject ' HWND ' ' Methods: ' AddBrowser ' AddLastOpen ' AddUsingCreationTime ' AddUsingTitle ' Class_Initialize ' Name ' ' Author: Anshoo Arora ' ' Start: October 02, 2009 ' ' Modified: '========================================= Class clsBrowser Private Handle Private m_hashTable '========================================= ' Name: Private Sub Class_Initialize ' ' Input: ' None ' ' Output: ' None ' ' Purpose: Initializes the Scripting.Dictionary Singleton ' ' Remarks: ' ' Author: ' ' Version: 0.1 '========================================= Private Sub Class_Initialize Dim bInit: bInit = False ' If colBrowser has already been instantiated, then Init = True If IsObject(colBrowser) Then If Not colBrowser Is Nothing Then bInit = True End If End If ' If colBrowser was destroyed or has not yet instantiated, then create it If bInit = False Then Set colBrowser = CreateObject("Scripting.Dictionary") ' colObject acts as a reference to colBrowser colObject = colBrowser End Sub '========================================= ' Name: Sub AddBrowser ' ' Input: ' sName - Name of the browser that is added to the global browser ' collection. ' ' Output: ' None ' ' Purpose: Adds a browser with the given name to the global collection ' object. ' ' Remarks: ' ' Author: ' ' Version: 0.1 '========================================= Private Sub AddBrowser(sName) ' If the Name already exists in the collection, then remove it so it can be re-added If colObject.Exists(sName) Then colObject.Remove sName colObject.Remove sName & "-HWND" End If ' Add the Browser with its corresponding handle ' Store the Handle Property With colObject .Add sName, Browser("hwnd:=" & Me.HWND) .Add sName & "-HWND", Me.HWND End With End Sub '========================================= ' Name: Sub AddUsingCreationTime ' ' Input: ' sName - Name of the Browser that is added to the collection ' intCreationTime - CreationTime value ' ' Output: ' None ' ' Purpose: Uses the "AddBrowser" method to add browsers to the collection using their CreationTime Property ' ' Remarks: ' ' Author: ' ' Version: 0.1 '========================================= Public Sub AddUsingCreationTime(sName, intCreationTime) Dim oBrowser, oCol ' Description object for Browser Class Set oBrowser = Description.Create oBrowser("micclass").Value = "Browser" ' ChildObjects of Browser Class Description Set oCol = Desktop.ChildObjects(oBrowser) ' If the supplied CreationTime is greater than the total number of open browsers, then Report Err. If intVal > oCol.Count Then Reporter.ReportEvent micWarning, "Add Browser Using CreationTime", "Browser with CreationTime " &intCreationTime& " was not found." Exit Sub End If ' Store the Browser Handle Me.HWND = Browser("creationtime:=" & intCreationTime).GetROProperty("HWND") ' Add the browser to the collection AddBrowser sName End Sub '========================================= ' Name: Sub AddUsingTitle ' ' Input: ' sName - Name of the Browser that is added to the collection ' sTitle - Title string of the Browser ' ' Output: ' None ' ' Purpose: Uses the "AddBrowser" method to add browsers to the collection using their Title Property ' ' Remarks: ' ' Author: ' ' Version: 0.1 '========================================= Public Sub AddUsingTitle(sName, sTitle) ' Verify if the browser with the supplied title exists If Not Browser("title:=" & sTitle).Exist(1) Then Reporter.ReportEvent micWarning, "Add Browser Using Title", "Browser with Title " &sTitle& " was not found." Exit Sub End If ' Store the Browser Handle Me.HWND = Browser("title:=" & sTitle).GetROProperty("HWND") ' Add the browser to the collection AddBrowser sName End Sub '========================================= ' Name: Sub AddLastOpen ' ' Input: ' sName - Name of the Browser that is added to the collection ' ' Output: ' None ' ' Purpose: Uses the "AddBrowser" method to add the last (most recent) open browser ' Note: The last open browser always has the greatest CreationTime ' ' Remarks: ' ' Author: ' ' Version: 0.1 '========================================= Public Sub AddLastOpen(sName) Dim oBrowser, oCol ' Description object for Browser Class Set oBrowser = Description.Create oBrowser("micclass").Value = "Browser" ' ChildObjects of Browser Class Description Set oCol = Desktop.ChildObjects(oBrowser) ' Store the Browser Handle Me.HWND = Browser("creationtime:=" & oCol.Count - 1).GetROProperty("HWND") ' Add the browser to the collection AddBrowser sName End Sub '========================================= ' Name: Sub ChangeName ' ' Input: ' ChangeFrom - Current Name ' ChangeTo - Name you want the browser to have ' ' Output: ' None ' ' Purpose: Changes the Key of the associated Browser. For example: ' A browser was saved with the name: "Main" ' This method can be called to change "Main" to some other name. ' Call BrowserObjectChangeName("Main", "Sub") ' ' Remarks: ' ' Author: ' ' Version: 0.1 '========================================= Public Sub ChangeName(ChangeFrom, ChangeTo) With colObject If .Exists(ChangeFrom) Then .Add ChangeTo, .Item(ChangeFrom) .Add ChangeTo & "-HWND", .Item(ChangeFrom & "-HWND") .Remove ChangeFrom .Remove ChangeFrom & "-HWND" End If End With End Sub '========================================= ' Name: Function Name ' ' Input: ' Key - Browser Name ' ' Output: ' None ' ' Purpose: ' ' Remarks: ' ' Author: ' ' Version: 0.1 '========================================= Public Function Name(Key) 'As Variant Dim Keys ' As Array ' Array of Keys Keys = colObject.Keys If IsNumeric(Key) Then Key = Keys(Key) End If If IsObject(colObject.Item(Key)) Then Set Name = colObject.Item(Key) Else Name = colObject.Item(Key) End If End Function '========================================= ' Name: Sub Destroy ' ' Input: ' None ' ' Output: ' None ' ' Purpose: Releases the Scripting.Dictionary Object ' ' Remarks: ' ' Author: ' ' Version: 0.1 '========================================= Public Sub Destroy Set colObject = Nothing End Sub '========================================= ' Name: Property Get HWND ' ' Input: ' None ' ' Output: ' Browser Handle ' ' Purpose: Releases the Scripting.Dictionary Object ' ' Remarks: ' ' Author: ' ' Version: 0.1 '========================================= Public Property Let HWND(ByVal Val) 'As Integer Handle = val End Property Public Property Get HWND() 'As Integer HWND = Handle End Property '========================================= ' Name: Property Get colObject ' ' Input: ' None ' ' Output: ' Object - Scripting.Dictionary ' ' Purpose: Stores the Browser Collection ' ' Remarks: ' ' Author: ' ' Version: 0.1 '========================================= Public Property Let colObject(ByRef Val) 'As Collection Set m_hashTable = Val End Property Public Property Get colObject() 'As Collection Set colObject = m_hashTable End Property End Class 'Instance of Class clsBrowser Set BrowserObject = New clsBrowser