Tutorial on Automating Logos4+ with ComApi in VBA

Pieter J.
Pieter J. Member Posts: 533
edited November 20 in English Forum

I searched the internet on automating the ComApi in VBA/VBS with little results. The best samples is mostly in C/C++ or something. Here is something that may be of interest and help. If anyone can provide some code samples it would be appreciated.

7318.L4VBATut.zip

«1

Comments

  • Rosie Perera
    Rosie Perera Member Posts: 26,202 ✭✭✭✭✭

    What is this bit about "This Tutorial requires LogosCom.exe"?

    There is no such file in all of Logos. The executable file for Logos is called Logos.exe.

  • Pieter J.
    Pieter J. Member Posts: 533

    Yes, that is true in a way. But technically, LogosCom.exe is the ComApi Type Library of Logos. When you add a Reference to the "Logos Bible Software 4 Type Library" in a VBA Project, it is actually pointing to the ActiveX (LogosCom.exe)  on your harddrive at %your Logos installation folder% \System\LogosCom.exe and not Logos.exe. Without the Type Library you can't interface with Logos.exe

    If for any random reason VBA or your Development Environment of choice says "Can't create ActiveX" you will know that this file either doesn't exist, is not properly registered or you do not have the right security privalages on the file or its directory structure. It's good to know this when working with the ComApi. I encountered this error several times in VBA, VBScript, JScript and .NET 2010 Express Edition on Win 7 and 8.

    I hope this explains the use of the filename LogosCom.exe

  • Randy W. Sims
    Randy W. Sims Member Posts: 2,272 ✭✭✭

    Nice tutorial! I like the way you put it together. I haven't looked at all the code samples in depth, just flipped through and ran a few of them. Looks very useful and very nicely put together.

  • Lynden O. Williams
    Lynden O. Williams MVP Posts: 8,979

    Mission: To serve God as He desires.

  • Randy W. Sims
    Randy W. Sims Member Posts: 2,272 ✭✭✭

    Randy, can you give a video demo?

    Sure. Here's a real quick screencast of the some of the power point tutorial. You may have to pause to examine some of the screens in more depth.

  • Pieter J.
    Pieter J. Member Posts: 533

    8037.Logos 4 COM API.zip

    Programming the ComApi starts with a workable Knowledge of how Objects attach to each other. Here is my interpretation of the ObjectModel ApiVersion 3. If for any reason I made a mistake on this map, please inform me to make the corrections. If you follow the links and info on this map you should be well away on interfacing with Logos. Start at the Left Node "StartUp" and follow the map to the right. Be carefull in using recursive programming on the LogosDataTypeReference because it returns properties containing LogosDataTypeReference (See the Green nodes).

  • Pieter J.
    Pieter J. Member Posts: 533

    I Paste some Code here for those that can't use or open VBA. The ClassModule have Functions that could be reused in some situations.

    PASTE THIS IN A CLASSMODULE IN VBA

    'Win32API - Just used for a Timer in Windows

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

    Dim Launcher As LogosLauncher
    Dim WithEvents Logos As LogosApplication

    Const ApiVersion = 3
    Const ClassName As String = "CLogos"

    Public Event CopyBibleVerse(Reference As String, BibleText As String)
    Public Event LibraryQuery(ResourceInfo As LogosResourceInfo)
    Public Event AOpenPanel(Panel As LogosPanel)

    Public Enum RenderStyles
        rsSHORT = 0
        rsMEDIUM = 1
        rsLONG = 2
        rsDEFAULT = 3
    End Enum
    Public Enum QueryDetails
        qdIMAGE = 0
        qdTITLE = 1
        qdTYPE = 2
        qdSERIES = 3
        qdSUBJECTS = 4
        qdAUTHER = 5
        qdMYTAGS = 6
        qdRATING = 7
        qdABTEVIATEDTITLE = 8
        qdELECTRONICPUBLICATIONDATE = 9
        qdLANGUAGES = 10
        qdPUBLICATIONDATE = 11
        qdPUBLISHER = 12
        qdLASTUPDATED = 13
        qdDEVICES = 14
        qdEDITION = 15
        qdLASTACCESSED = 16
        qdMOSTUSED = 17
        qdCOMMUNITYTAGS = 18
    End Enum
    Sub Create(Optional CommandLineArguments As String)
        On Error GoTo ErrHandler
        Set Launcher = New LogosLauncher
        Set Logos = Nothing
        
        Stop
        Launcher.LaunchApplication CommandLineArguments
        While Logos Is Nothing
            Set Logos = Launcher.Application
        Wend
        
        If Logos.ApiVersion < ApiVersion Then _
            MsgBox "ApiVersion " & ApiVersion & _
                " Required." & vbCrLf & _
                "You have " & Logos.ApiVersion & vbCrLf & _
                "The Logos Class may not Function correctly", vbCritical, ClassName
       Exit Sub
    ErrHandler:
       MsgBox Err.Number & " - " & Err.Description
       Err.Clear
    End Sub
    Public Function GetResourceInfo(ResourceId As String) As LogosResourceInfo
        Stop
        Set GetResourceInfo = Logos.Library.GetResourceInfo(ResourceId)
    End Function
    Property Get Application() As LogosApplication
        If Logos Is Nothing Then
            MsgBox "Use Create first", vbInformation, Title
            Else
            Set Application = Logos
        End If
    End Property

    Sub CopyBibleVerses(BibleReferences As String, Optional RenderStyle As RenderStyles = rsDEFAULT)
        Dim LDTPRC As LogosDataTypeParsedReferenceCollection
        Dim LDTPR As LogosDataTypeParsedReference
        Dim LCBVR As LogosCopyBibleVersesRequest
        
        If Logos Is Nothing Then GoTo NoLogos
        'Scan first to check if there is more than one
            Stop
            Set LDTPRC = Logos.DataTypes.GetDataType("Bible").ScanForReferences(BibleReferences)
            If LDTPRC.Count > 0 Then
                For Each LDTPR In LDTPRC
                    Set LCBVR = Logos.CopyBibleVerses.CreateRequest
                    LCBVR.Reference = LDTPR.Reference
                    RaiseEvent CopyBibleVerse(LDTPR.Reference.Render(GetRenderStyle(RenderStyle)), Logos.CopyBibleVerses.GetText(LCBVR))
                Next
            Else
                    'This will not run because all refrences are handled above
                    'This is only to show how to do a CopyBibleVerseRequest
                    'with one Reference another way
                    Set LCBVR = Logos.CopyBibleVerses.CreateRequest
                    LCBVR.Reference = Logos.DataTypes.GetDataType("Bible").ParseReference(BibleReferences)
                    RaiseEvent CopyBibleVerse(LCBVR.Reference.Render(GetRenderStyle(RenderStyle)), _
                        Logos.CopyBibleVerses.GetText(LCBVR))
            End If
        Exit Sub
    NoLogos:
        MsgBox "Use Create First", vbInformation, Title
    ErrHandler:
        MsgBox Err.Number & " - " & Err.Description
        Err.Clear
    End Sub
    Private Function GetRenderStyle(rs As RenderStyles) As String
        Stop
        Select Case rs
            Case rsSHORT
                GetRenderStyle = "short"
            Case rsMEDIUM
                GetRenderStyle = "medium"
            Case rsLONG
                GetRenderStyle = "long"
            Case rsDEFAULT
                GetRenderStyle = "default"
        End Select
    End Function

    Sub QueryLibraryByDetails(QueryByDetail As QueryDetails, SearchString As String)
        Dim strDetail As String: getQueryDetail (querybydetails)
        Dim RIC As LogosResourceInfoCollection
        Dim RI As LogosResourceInfo
        Stop
        Set RIC = Logos.Library.GetResourcesMatchingQuery(getQueryDetail(QueryByDetail) & SearchString)
        For Each RI In RIC
            RaiseEvent LibraryQuery(RI)
        Next
    End Sub
     Sub QueryLibraryByResourceType(ResourceType As String)
        Dim RIC As LogosResourceInfoCollection
        Dim RI As LogosResourceInfo
        Stop
        Set RIC = Logos.Library.GetResourcesByResourceType(ResourceType)
        For Each RI In RIC
            RaiseEvent LibraryQuery(RI)
        Next
     End Sub
    Private Function getQueryDetail(qd As QueryDetails) As String
        Select Case qd
            Case qdIMAGE
                getQueryDetail = "Image:"
            Case qdTITLE
                getQueryDetail = "Title:"
            Case qdTYPE
                getQueryDetail = "Type:"
            Case qdSERIES
                getQueryDetail = "Series:"
            Case qdSUBJECTS
                getQueryDetail = "Subjects:"
            Case qdAUTHER
                getQueryDetail = "Auther:"
            Case qdMYTAGS
                getQueryDetail = "MyTags:"
            Case qdRATING
                getQueryDetail = "Rating:"
            Case qdABTEVIATEDTITLE
                getQueryDetail = "AbbreviatedTitle:"
            Case qdELECTRONICPUBLICATIONDATE
                getQueryDetail = "ElectronicPublicationDate:"
            Case qdLANGUAGES
                getQueryDetail = "Languages:"
            Case qdPUBLICATIONDATE
                getQueryDetail = "PublicationDate:"
            Case qdPUBLISHER
                getQueryDetail = "Publisher:"
            Case qdLASTUPDATED
                getQueryDetail = "LastUpdated:"
            Case qdDEVICES
                getQueryDetail = "Devices:"
            Case qdEDITION
                getQueryDetail = "Edition:"
            Case qdLASTACCESSED
                getQueryDetail = "LastAccessed:"
            Case qdMOSTUSED
                getQueryDetail = "MostUsed:"
            Case qdCOMMUNITYTAGS
                getQueryDetail = "CommunityTags:"
        End Select
    End Function

    Sub GetOpenPanels()
        Dim OP As LogosPanel
        For Each OP In Logos.GetOpenPanels
            RaiseEvent AOpenPanel(OP)
        Next
    End Sub
    Private Sub Logos_Exiting()
        Stop
    End Sub

    Private Sub Logos_PanelActivated(ByVal Panel As Object)
        Stop
    End Sub

    Private Sub Logos_PanelChanged(ByVal Panel As Object, ByVal Hint As Object)
        Stop
    End Sub

    Private Sub Logos_PanelClosed(ByVal Panel As Object)
        Stop
    End Sub

    Private Sub Logos_PanelOpened(ByVal Panel As Object)
        Stop
    End Sub

    Function GetNavigationRequestFromActivePanel()
        Stop
        'First I'll open the esv Bible
        'I use LoadReference to get the ref to Gen 1:1 formatted for ExecuteUri
        'You can use "bible.Gen 1:1" and there is other ways to get to this ref as well
        'This is just to show how to use LoadReference
        'and to open a Resource for the Navigation Sample
        Debug.Print Logos.DataTypes.LoadReference("bible.Gen 1:1").Save
        Logos.ExecuteUri "logosres:esv;ref=" & Logos.DataTypes.LoadReference("bible.Gen 1:1").Save
        
        Stop
        'With the following code you should keep in mind
        'There are different kinds of Panels
        
        Dim AP As LogosPanel
        Dim NR As LogosNavigationRequest
        'Take note that the following will contain info for
        'Reference Or Headword
        'This means the info inside LogosReferenceOrHeadwordCollection and LogosReferenceOrHeadword
        'may be either Reference OR Headword
        Dim HC As LogosReferenceOrHeadwordCollection
        Dim H As LogosReferenceOrHeadword
        
        Set AP = Logos.GetActivePanel
     
        If AP.DetailsKind = "Resource" Then
            Debug.Print "Now we know we can use Panel.Details"
            Debug.Print "It Return LogosResourcePanelDetails containing the ResourceId: " & AP.Details.ResourceId
            Set NR = Logos.CreateNavigationRequest
            Set HC = AP.GetCurrentReferencesAndHeadwords
            If HC.Count > 0 Then
                With NR
                    .Headword = HC.Item(0).Headword
                    .HeadwordLanguage = HC.Item(0).HeadwordLanguage
                    .Reference = HC.Item(0).Reference
                    .ResourceId = AP.Details.ResourceId
                End With
            End If
            Stop
            
            'I'll Close All in Logos so we can See the Navigation take place
            Logos.Activate
            SendKeys "%D", True
            SendKeys "Close All", True
            Sleep 2000
            SendKeys "{ENTER}", True
            

            
            Stop
            Logos.Navigate NR
            
            Stop
            'We can use the Info from the Panel to create an Uri
            Debug.Print "logosres:" & NR.ResourceId & ";ref=" & NR.Reference.Save
            'We can use that Uri to ExecuteUri
            
            Stop
            'I'll Close All in Logos so we can See the ExecuteUri take place
            Logos.Activate
            SendKeys "%D", True
            SendKeys "Close All", True
            Sleep 2000
            SendKeys "{ENTER}", True

            Stop
            Logos.ExecuteUri "logosres:" & NR.ResourceId & ";ref=" & NR.Reference.Save
        End If
        
        Stop
        'The above is a Startingpoint for a more complex way
        'to generate NavigationRequests or Uri's for different Panels
        'eg: logos4:Explorer;ref=BibleESV.Ge1.1 using logos4:(Panel.Kind obtained)
        'This way you can generate Uri's for external links from Active Panels
        'Just use your imagination
        
    End Function

    PASTE THIS IN A FORM IN VBA

    Public WithEvents Logos As CLOgos

    Private Sub Logos_AOpenPanel(Panel As Logos4Lib.LogosPanel)
        Debug.Print Panel.Title
    End Sub

    Private Sub Logos_CopyBibleVerse(Reference As String, BibleText As String)
        Debug.Print Reference & vbCrLf & vbTab & BibleText
    End Sub

    Private Sub Logos_LibraryQuery(ResourceInfo As Logos4Lib.LogosResourceInfo)
        Debug.Print ResourceInfo.Title
        Stop
    End Sub

    Private Sub UserForm_Initialize()
        MsgBox "This shows the complicated part of ComApi" & vbCrLf & _
            "The rest seems to be easy and straight forward"
            
        Set Logos = New CLOgos
        
        Stop
        'Create Logos
        Logos.Create
        
        Stop
        'Single Reference
        Logos.CopyBibleVerses "Joh 3:16", rsMEDIUM
        
        Stop
        'Or Multiple References
        Logos.CopyBibleVerses "Gen 1:1 AND maybe Rev 4:8 and Lev 4:3", rsLONG
         
        Stop
        'Library Query
        Logos.QueryLibraryByDetails qdTITLE, "Bible"
        
        Stop
        'Library Query By ResourceType
        Logos.QueryLibraryByResourceType "text.monograph"
        
        Stop
        'The following is to demonstrate how to get ResourceInfo
        'using ResourceId
        Dim RI As LogosResourceInfo
        Set RI = Logos.GetResourceInfo("LLS:1.0.710")
        Debug.Print RI.Title, RI.ResourceId
        'Not the ResourceId returned by ResourceInfo.ResourceId
        Set RI = Logos.GetResourceInfo("esv")
        If RI Is Nothing Then Debug.Print "Returned NOTHING"
        
        Stop
        'How to Use GetOpenPanels
        Logos.GetOpenPanels
        
        Stop
        'I'll demonstrate Application.CreateNavigationRequest and
        'Application.Navigate using GetActivePanel
        Logos.GetNavigationRequestFromActivePanel
        
    End Sub

    RUN THE FORM

    It will Pause itself throughout the Code to show you how to use the API

  • steve clark
    steve clark Member Posts: 3,591 ✭✭✭

    I Paste some Code here for those that can't use or open VBA. The ClassModule have Functions that could be reused in some situations.

    Interesting Pieter

    Especially the part of the code which inserted text into L4's command box, but it was not executed in L4.

    EDIT: text from DbugPrint  4428.Pieter's dump to debug.txt

    QLinks, Bibl2, LLR, Macros
    Dell Insp 17-5748, i5, 1.7 GHz, 8G RAM, win 8.1

  • Pieter J.
    Pieter J. Member Posts: 533

    The execution of the SendKeys could cause trouble depending on the speed of your system. Type in "Close All" in your CommandBox and take note of the time delay until the dropdown lists the Close All command. Use that time delay x 1000 in the Sleep command. That should be the delay you normally need.

            Logos.Activate
            SendKeys "%D", True
            SendKeys "Close All", True
            Sleep [TimeDelay in milliseconds]
            SendKeys "{ENTER}", True

    Another reason could also be that in those 2 sec delay you probably switched focus to VBA. To make sure the command gets to Logos, insert an Actiavte command before the {ENTER}:

          Sleep [TimeDelay in milliseconds]

           Logos.Activate
           SendKeys "{ENTER}", True

  • Pieter J.
    Pieter J. Member Posts: 533

    Suppose I need to read the Logos Help Manual before trying to use SendKeys.Here is a Class to SendKeys a better way.

    WARNING: Do not Break into the CDoCmd.DoCmd Procedure and debug because if Logos doesn't have Focus the Keystrokes will be send to VBA. Rather just check if the SendKeys Keystrokes are correct because I did not check them all, I just wrote them quickly.


    Sample: Logos.DoCmd kbs_close_all_panels

    Preparations in CLogos Class:
    Add to the Globals of CLogos Class: Dim KBS As CDoCmd
    In CLogos Class at Sub Create(Optional CommandLineArguments As String), Add: Set KBS = New CDoCmd
    In CLogos Add:

    Public Sub DoCmd(eKBS As LogosKeyboardShortCuts)
        KBS.DoCmd eKBS, Logos
    End Sub

    A New Class CDoCmd:
    Add The Following Class in VBA with the name CDoCmd

    'SENDKEYS FOR LOGOS4+
    Public Enum LogosKeyboardShortCuts
        kbs_activate_window_menu = 0
        kbs_add_current_location_to_Favorites = 1
        kbs_apply_visual_markup = 2
        kbs_clone_this_panel_in_a_new_tab = 3
        kbs_close_current_panel = 4
        kbs_close_panel = 5
        kbs_close_all_panels = 6
        kbs_close_program = 7
        kbs_copy = 8
        kbs_copy_ins = 9
        kbs_cut = 10
        kbs_cut_del = 11
        kbs_delete = 12
        kbs_dismiss_or_exit_drawing_mode = 13
        kbs_enter_drawing_mode_or_clear_drawing = 14
        kbs_erase_visual_markup = 15
        kbs_expand_all_timeline_groups = 16
        kbs_forces_sign_in_prompt_at_startup = 17
        kbs_go_to_Command_Box = 18
        kbs_go_to_Home_Page_from_a_floating_window = 19
        kbs_switch_home = 20
        kbs_go_to_menu_bar = 21
        kbs_go_to_next_tab = 22
        kbs_go_to_previous_tab = 23
        kbs_go_to_reference_box_of_current_resource_OR_guide = 24
        kbs_help = 25
        kbs_next = 26
        kbs_next_equivalent_resource = 27
        kbs_open_History = 28
        kbs_open_Library_in_a_floating_window = 29
        kbs_open_Search_from_a_floating_window = 30
        kbs_open_Search_panel = 31
        kbs_open_OR_close_Customize_home_page_menu = 32
        kbs_open_OR_close_File_menu = 33
        kbs_open_OR_close_Guides_menu = 34
        kbs_open_OR_close_Help_menu = 35
        kbs_open_OR_close_Home_Page = 36
        kbs_open_OR_close_Layouts = 37
        kbs_open_OR_close_Library = 38
        kbs_open_OR_close_Tools_menu = 39
        kbs_paste = 40
        kbs_paste_ins = 41
        kbs_previous = 42
        kbs_previous_equivalent_resource = 43
        kbs_print  = 44
        kbs_quick_comparison_of_the_active_verse_OR_selected_text = 45
        kbs_redo = 46
        kbs_refresh = 47
        kbs_search_for_word_OR_phrase_in_Entire_Library = 48
        kbs_search_for_word_OR_phrase_in_Top_Bibles = 49
        kbs_select_all = 50
        kbs_set_Bookmark_1 = 51
        kbs_switch_keyboard_focus_to_next_panel = 52
        kbs_switch_keyboard_focus_to_previous_panel = 53
        kbs_switch_to_next_tab = 54
        kbs_switch_to_previous_tab = 55
        kbs_undo = 56
        kbs_undo_z = 57
        kbs_zoom_in = 58
        kbs_zoom_out = 59
        kbs_zoom_to_fit = 60
        kbs_copy_location_as_URL_HTML_WIKI_RL = 61
        kbs_find_in_this_panel = 62
        kbs_read_aloud = 63
        kbs_reading_view = 64
        kbs_show_OR_hide_interlinear_pane = 65
        kbs_show_OR_hide_locator_bar = 66
        kbs_show_OR_hide_table_of_contents = 67
    End Enum

    Public Sub DoCmd(KBS As LogosKeyboardShortCuts, L As LogosApplication)
        L.Activate
     Select Case KBS
            Case kbs_activate_window_menu: SendKeys "% ", True
            Case kbs_add_current_location_to_Favorites: SendKeys "^d", True
            Case kbs_apply_visual_markup: SendKeys "^k", True
            Case kbs_clone_this_panel_in_a_new_tab: SendKeys "^+n", True
            Case kbs_close_current_panel: SendKeys "^{F4}", True
            Case kbs_close_panel: SendKeys "^w", True
            Case kbs_close_all_panels: SendKeys "^+w", True
            Case kbs_close_program: SendKeys "%{F4}", True
            Case kbs_copy: SendKeys "^c", True
            Case kbs_copy_ins: SendKeys "^{INS}", True
            Case kbs_cut: SendKeys "^x", True
            Case kbs_cut_del: SendKeys "+{DEL}", True
            Case kbs_delete: SendKeys "{DEL}", True
            Case kbs_dismiss_or_exit_drawing_mode: SendKeys "{Esc}", True
            Case kbs_enter_drawing_mode_or_clear_drawing: SendKeys "{F8}", True
            Case kbs_erase_visual_markup: SendKeys "^+k", True
            Case kbs_expand_all_timeline_groups: SendKeys "^e", True
            Case kbs_forces_sign_in_prompt_at_startup: SendKeys "^", True
            Case kbs_go_to_Command_Box: SendKeys "%d", True
            Case kbs_go_to_Home_Page_from_a_floating_window: SendKeys "%{HOME}", True
            Case kbs_switch_home: SendKeys "{F10}", True
            Case kbs_go_to_menu_bar: SendKeys "%", True
            Case kbs_go_to_next_tab: SendKeys "^{TAB}", True
            Case kbs_go_to_previous_tab: SendKeys "^+{TAB}", True
            Case kbs_go_to_reference_box_of_current_resource_OR_guide: SendKeys "^g", True
            Case kbs_help: SendKeys "{F1}", True
            Case kbs_next: SendKeys "%{DOWN}", True
            Case kbs_next_equivalent_resource: SendKeys "^+{RIGHT}", True
            Case kbs_open_History: SendKeys "^h", True
            Case kbs_open_Library_in_a_floating_window: SendKeys "^l", True
            Case kbs_open_Search_from_a_floating_window: SendKeys "^+s", True
            Case kbs_open_Search_panel: SendKeys "%s", True
            Case kbs_open_OR_close_Customize_home_page_menu: SendKeys "%c", True
            Case kbs_open_OR_close_File_menu: SendKeys "%f", True
            Case kbs_open_OR_close_Guides_menu: SendKeys "%g", True
            Case kbs_open_OR_close_Help_menu: SendKeys "%p", True
            Case kbs_open_OR_close_Home_Page: SendKeys "%h", True
            Case kbs_open_OR_close_Layouts: SendKeys "%a", True
            Case kbs_open_OR_close_Library: SendKeys "%l", True
            Case kbs_open_OR_close_Tools_menu: SendKeys "%t", True
            Case kbs_paste: SendKeys "^v", True
            Case kbs_paste_ins: SendKeys "+{INS}", True
            Case kbs_previous: SendKeys "%{UP}", True
            Case kbs_previous_equivalent_resource: SendKeys "^+{LEFT}", True
            Case kbs_print : SendKeys "^p", True
            Case kbs_quick_comparison_of_the_active_verse_OR_selected_text: SendKeys "{F7}", True
            Case kbs_redo: SendKeys "^y", True
            Case kbs_refresh: SendKeys "{F5}", True
            Case kbs_search_for_word_OR_phrase_in_Entire_Library: SendKeys "^+{ENTER}", True
            Case kbs_search_for_word_OR_phrase_in_Top_Bibles: SendKeys "^{ENTER}", True
            Case kbs_select_all: SendKeys "^a", True
            Case kbs_set_Bookmark_1: SendKeys "^+1", True
            Case kbs_switch_keyboard_focus_to_next_panel: SendKeys "^{F6}", True
            Case kbs_switch_keyboard_focus_to_previous_panel: SendKeys "^+{F6}", True
            Case kbs_switch_to_next_tab: SendKeys "^{PGDN}", True
            Case kbs_switch_to_previous_tab: SendKeys "^{PGUP}", True
            Case kbs_undo: SendKeys "%{BACKSPACE}", True
            Case kbs_undo_z: SendKeys "^z", True
            Case kbs_zoom_in: SendKeys "^=", True
            Case kbs_zoom_out: SendKeys "^-", True
            Case kbs_zoom_to_fit: SendKeys "^0", True
            Case kbs_copy_location_as_URL_HTML_WIKI_RL: SendKeys "^%c", True
            Case kbs_find_in_this_panel:  SendKeys "^f", True
            Case kbs_read_aloud: SendKeys "^r", True
            Case kbs_reading_view: SendKeys "{F11}", True
            Case kbs_show_OR_hide_interlinear_pane: SendKeys "^+r", True
            Case kbs_show_OR_hide_locator_bar: SendKeys "^+l", True
            Case kbs_show_OR_hide_table_of_contents: SendKeys "^+c", True
        End Select
    End Sub

    Back in CLogos:
    In Class CLogos, replace:
            Logos.Activate
            SendKeys "%D", True
            SendKeys "Close All", True
            Sleep 2000
            SendKeys "{ENTER}", True
    With:
        DoCmd kbs_close_all_panels

    How to Use:
    Now from the Form you can use: Logos.DoCmd kbs_close_all_panels
    You can use this class in any app with the following Syntax:
        DoCmd LogosKeyBoardShortCuts, LogosApplication

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    This is incredibly useful - thanks for sharing! I have been wondering if such a thing was possible with Logos. 

    I have been unable to make this work, however - I imagine because I am using Verbum??

    I have the LogosCom.EXE file, and the reference appears correctly in VBA to the file. However, whenever the code gets to:

    oLauncher.LaunchApplication

    it returns error 13, "Type Mismatch". Then if I go into Debug mode, and run through the code line by line, at oLauncher.LaunchApplication it gives the error: "Method 'LaunchApplication' of object 'ILogosLauncher' failed" (Run-time error -2147417851 (80010105). 

    This happens regardless if Verbum is open or not. Any ideas?

  • Pieter J.
    Pieter J. Member Posts: 533

    I could only advise you on how I would start debugging if I ran into this error. The following is by no means expert advice or even technically correct.

    I used Logos Bible Software 5.2a SR-1 (5.2.1.0081) with Api Version 3  (5.2.1.81). I do not know if the ComApi also updates automatically.

    1. My first guess would be Version incompatibility between Logos Bible Software and the ComApi because of the fact that it accured on oLauncher.LaunchApplication. Because Nothing is being Set on the VBA side the TypeMismatch could come from the external source being Referenced.
    2. Second guess would be that there are 2 LogosCom.exe versions on your system. One being registered in windows and the other being Referenced in VBA.

    I would try to Create the Launcher with late binding first (I did not test this, just wrote it here):

    Sub Test()

        Dim oLauncher    'DO NOT USE As LogosLauncher HERE

        on error goto ErrHandler

        Set oLauncher = CreateObject("LogosBibleSoftware.Launcher") 'The version independent ProgID

        oLauncher.LaunchApplication

        Beep 'If we get here it works"

        stop 

    Exit Sub

    ErrHandler:

        Beep: Beep

        stop

        Debug.Print Err.Number & " - " & Err.Description

    End Sub

    If this worked, search if there is another LogosCom.exe file on your system.

    Hope this directs you into a meaningfull debug session.

  • steve clark
    steve clark Member Posts: 3,591 ✭✭✭

    This happens regardless if Verbum is open or not. Any ideas?

    When i copied Pieter's code (a few posts above), i had to:

    1. Setup a Reference to Logos' API  (click an image below to view full size)

         

    2. Had to name the Class to what Pieter had named his Class

    Here is my Excel file with Pieter's stuff (class renamed) 3443.Book1.zip
    (had to zip the Excel file because the forum editor doesn't allow files with macros, so you will need to unzip the file.

    More steps

    • When you open the Excel file, it will give you a warning that it contains Macros, so click on the gold bar & allow it to run the macros.
    • Another thought, i would try opening Verbum before running the macro  (see you already tried this)
    • On the worksheet you will see a single button, click it once to start Pieter's macro.

    QLinks, Bibl2, LLR, Macros
    Dell Insp 17-5748, i5, 1.7 GHz, 8G RAM, win 8.1

  • steve clark
    steve clark Member Posts: 3,591 ✭✭✭

    Suppose I need to read the Logos Help Manual before trying to use SendKeys.Here is a Class to SendKeys a better way.

    It is working now, i had to allow more time since i am running on a slow computer (see my PC specs below in my signature).

    Thanks Pieter for your hard work!

    btw, how do you see this api being used inside of an Office app? i am curious.

    It seems you can use it to copy Bible verses, open a panel inside of L4, get book names in your library. Guess i am not looking outside the box to see how i would use this info inside of Excel for instance, except to get a list of my L4 library. To copy Bible verses into Excel seems like a lot of work to use the api. Figure you already have ideas on what you are trying to do with the api inside your Office apps. So i would be curious how you see using this.

    QLinks, Bibl2, LLR, Macros
    Dell Insp 17-5748, i5, 1.7 GHz, 8G RAM, win 8.1

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    I would try to Create the Launcher with late binding first (I did not test this, just wrote it here):

    Sub Test()

        Dim oLauncher    'DO NOT USE As LogosLauncher HERE

        on error goto ErrHandler

        Set oLauncher = CreateObject("LogosBibleSoftware.Launcher") 'The version independent ProgID

        oLauncher.LaunchApplication

        Beep 'If we get here it works"

        stop 

    Exit Sub

    ErrHandler:

        Beep: Beep

        stop

        Debug.Print Err.Number & " - " & Err.Description

    End Sub

    If this worked, search if there is another LogosCom.exe file on your system.

    Hope this directs you into a meaningfull debug session.

    Thanks for the help. The code seemingly completes correctly Set oLauncher = CreateObject("LogosBibleSoftware.Launcher"). But then, on oLauncher.LaunchApplication it errors out.

    The Debug.Print returns:

    -2147417851 - Automation error
    The server threw an exception.

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    This happens regardless if Verbum is open or not. Any ideas?

    When i copied Pieter's code (a few posts above), i had to:

    1. Setup a Reference to Logos' API  (click an image below to view full size)

         

    2. Had to name the Class to what Pieter had named his Class

    Here is my Excel file with Pieter's stuff (class renamed) 3443.Book1.zip
    (had to zip the Excel file because the forum editor doesn't allow files with macros, so you will need to unzip the file.

    More steps

    • When you open the Excel file, it will give you a warning that it contains Macros, so click on the gold bar & allow it to run the macros.
    • Another thought, i would try opening Verbum before running the macro  (see you already tried this)
    • On the worksheet you will see a single button, click it once to start Pieter's macro.

    Thanks for the help. Here is my Reference window. Everything seems to be correct as far as I can tell:

    When I click on the button in your Excel Sheet I get the following pop-up:

    The code then runs to the "Stop". I then run through the code with F8 line by line.

    Debug.Print outputs "-- Created -- Logos class"

    The code moves on to the Create subroutine. Then, on the line of code "Launcher.LaunchApplication CommandLineArguments" it errors out. Here is the message:

    Maybe someone from Logos could run a test on a Verbum system to confirm if it is a Verbum bug?

  • steve clark
    steve clark Member Posts: 3,591 ✭✭✭

    The code then runs to the "Stop". I then run through the code with F8 line by line.

    Sounds like you have done everything right...

    you might try using F5 instead (which will run to the next breakpoint), perhaps the stepping line by line is interrupting something timing-wise (just a guess).

    EDIT:

    Debug.Print outputs "-- Created -- Logos class"

    i added a few extra Debug.Print statements (like this) to help me recognize when things were being added to the debug window (some steps added a lot of stuff).

    QLinks, Bibl2, LLR, Macros
    Dell Insp 17-5748, i5, 1.7 GHz, 8G RAM, win 8.1

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    you might try using F5 instead (which will run to the next breakpoint), perhaps the stepping line by line is interrupting something timing-wise (just a guess).

    Errors out at the same moment, although the error box is slightly more detailed (same error number, though):

  • steve clark
    steve clark Member Posts: 3,591 ✭✭✭

    Errors out at the same moment, although the error box is slightly more detailed (same error number, though):

    This does sound like a Verbum issue.

    But to cover all basis, below are images of how i have Excel Options set (File->Options)
    [click images for full-size viewing]

                 

    A long time ago, i had to fiddle with the Macros permission; i may have fiddled with a few other permissions too. So the above settings are what i have now.

    QLinks, Bibl2, LLR, Macros
    Dell Insp 17-5748, i5, 1.7 GHz, 8G RAM, win 8.1

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    This does sound like a Verbum issue.

    But to cover all basis, below are images of how i have Excel Options set (File->Options)

    I set my options as yours, and the error is the same.

  • steve clark
    steve clark Member Posts: 3,591 ✭✭✭

    I set my options as yours, and the error is the same.

    Maybe Bradley Grainger will see this post and check into this issue using Verbum. Sounds like you have tried everything.

    P.S.  He is the Logos person who added all the LogosAPI stuff to the Logos wiki page.

    QLinks, Bibl2, LLR, Macros
    Dell Insp 17-5748, i5, 1.7 GHz, 8G RAM, win 8.1

  • Don Awalt
    Don Awalt Member Posts: 3,521 ✭✭✭

    Just a thought, I wonder if your Excel, Office Library, .NET Framework versions, and if there is anything else being used, are the same...

  • Pieter J.
    Pieter J. Member Posts: 533

    Try to Run your document as administrator. Maybe there's a mixup in privilages? I don't think Verbum is the issue because if I understand it correctly it uses the same Engine as the other packages.

  • steve clark
    steve clark Member Posts: 3,591 ✭✭✭

    Don Awalt said:

    Just a thought, I wonder if your Excel, Office Library, .NET Framework versions, and if there is anything else being used, are the same...

    i am running L4 ver 4.5c SR-5, which uses .NET ver 3.5 (if i remember correctly).

    Pieter mentioned earlier in this post that he is using L5 ver 5.2a SR-1, which uses .NET ver 4. Which would indicate that the LogosCom.exe works with both versions of .NET. Edit: (not necessarily true, windows can run both versions of .NET, but will require them to be installed separately)

    Which brings to mind a possibly important point, Fr. Devin Roza are you running the 64-bit version of Office? my version is obviously a 32-bit version of Office (i am running 32-bit Vista OS). Edit: Pieter, are you running a 64-bit version of Office? Or are you running a 32-bit version of Office? (i don't know how Office deals with its code structure when communicating with api's when there is a significant difference between underlying assembly structures).

    QLinks, Bibl2, LLR, Macros
    Dell Insp 17-5748, i5, 1.7 GHz, 8G RAM, win 8.1

  • Fr Devin Roza
    Fr Devin Roza MVP Posts: 2,413

    Which brings to mind a possibly important point, Fr. Devin Roza are you running the 64-bit version of Office? my version is obviously a 32-bit version of Office (i am running 32-bit Vista OS). Edit: Pieter, are you running a 64-bit version of Office? Or are you running a 32-bit version of Office? (i don't know how Office deals with its code structure when communicating with api's when there is a significant difference between underlying assembly structures).

    32 bit Office 2010 on 64 bit Windows 8.1 (which includes by default .NET 4.5).

    I wonder if Verbum causes problems because the name of the Executable is different.

    I use Verbum 5.2a SR-1. I use VBA quite a bit as well, and don't normally have any problem using API's within VBA. I'm pretty sure it is a Verbum related bug. Hopefully someone else can test with Verbum (ideally Bradley of course) and confirm if that is the case.

  • steve clark
    steve clark Member Posts: 3,591 ✭✭✭

    FYI

    Here is an Excel file with macro to determine which OS & Office version it is (64 or 32 bit). It is zipped since it contains a macro.

    7762.VersionButton.zip

    QLinks, Bibl2, LLR, Macros
    Dell Insp 17-5748, i5, 1.7 GHz, 8G RAM, win 8.1

  • Bradley Grainger (Logos)
    Bradley Grainger (Logos) Administrator, Logos Employee Posts: 11,969

    I wonder if Verbum causes problems because the name of the Executable is different.

    Yes, that could be an issue. We'll investigate.

  • Pieter J.
    Pieter J. Member Posts: 533

    btw, how do you see this api being used inside of an Office app? i am curious.

    The best answer is always a Sample (3157.AnaliseLNData.zip provided as is, not well commented and not cleaned up [Logos 5.2a SR-2 (5.2.1.0098)  | ComApi 3 | Office 2010 32bit | Win8 64bit]).

    Input: ESV Louw-Nida data

    Output: Summary of Louw-Nida Domains

    1. Open the Excel Workbook
    2. Open the ESV
    3. Turn on the Display for Louw-Nida on the ESV
    4. select Desired Verses
    5. Click Analise Selected ESV Button in Workbook on Sheet > Graph Domains
    6. Filter the PivotTable as Desired

    Analysis: Without reading the passage the summary tells me that the passage contains valuable information about Relations, Attitudes and Emotions and maybe it's worth looking into Afformation and Negation etc... I would therefore spend more time on these domains when analising the passage in Greek.

    Here is a Screenshot of a Filter and ChartType change of the Results in Excel:

    LogosComApi:

    1. I used the API to ScanForReferences to the Louw Nida DataType and one of the Keyboard SendKeys to copy selected text to the Clipboard

    Thoughts:

    Maybe this is possible in Logos, I've tried it once by grouping some stuff in SearchResults.

    What if I want to know how Israel traveled geographically in Genesis to Exodus. And then I want to compare the usage of all the terms they used to refer to the Creator. As a result I would be able to see if there is any relationship between the two. Did Israel prefer a certain usage in Egypt and another in other places? I did this once using the Export function in Logos. But a Macro could cut the time about 90%. I'm still investigating this idea.

    I would like Word to scroll to References/Headwords etc. in the Active Document while in Logos or to Navigate Logos automatically while in Word. Using CompareTo and Intersect of the ComAPI would help doing this. Usefull for PBB.

    Other ideas would be to automatically link FreeMind or FreePlane ideas as I work in those apps. Even linking Active Panels to ideas to leave a trail on my research and to have everything (Clippings|Notes|Passage Lists etc.) linked to a single map. It would be nice if I can drop a Panel in an app and it would create a link.

    Most of all - This is fun and if I can improve my Sermon Prep while having fun,  it's a win win situation.

  • steve clark
    steve clark Member Posts: 3,591 ✭✭✭

    The best answer is always a Sample (provided as is, not well commented and not cleaned up)

    Pieter, thank you for sharing your example!

    After spending a little time walking thru your macro i see there are much more possibilities than i had imagined or realized! i also see that your Box is much larger than my box (in relation to programming & depth of understanding the mechanisms for the ComApi 3). This will give me much to ponder and experiment with.

    Thank you very much for sharing! It is amazing the gifts our Lord has blessed you with (i have not met a Pastor who has an understanding of programming before). i envy pastor's understanding of original languages of the Bible (but understand that is not a talent/gift/desire the Lord has given me). From your example i see a little how someone with your background and programming skills can make use of the ComApi.

    May our Lord continue to bless you Sir!

    your humble brother in Christ

    QLinks, Bibl2, LLR, Macros
    Dell Insp 17-5748, i5, 1.7 GHz, 8G RAM, win 8.1